I have developed a website with login and signup. Inside that website it contains a wordpress blog int he folder “blog”. What i need to check whether the user is logged in or not in the blog. So i can put button like “login”-if not signed in and “dashboard”-if signed in
In parent folder’s php file, i wrote like this
<?php
session_start();
$_SESSION['username'] = $_POST['username'];
.......
.......
?>
and i used the following code in wordpress blog’s php file, to check whether user have logged and display username.
<?php
session_start();
echo $_SESSION['username'];
....
....
?>
But it gives me and error like this and doesn’t display the username
“Warning: session_start(): Cannot send session cache limiter – headers already sent (output started at C:xampphtdocsit-itechblogwp-includesgeneral-template.php:2343) in C:xampphtdocsit-itechblogwp-contentthemesdazzlingheader.php on line 42”
this error occurred because the output was sent before the session was started you need to go this page
header.php
: on line number: 42 where you have included the file namedgeneral-template.php
and see it does not give an output before the session gets started.try to use this in you theme’s functions.php
You should only be editing your theme files. It sounds like you may have been editing WordPress core files. Your session_start(); should go in the very top of header.php in /wp-content/themes/dazzling/ and ideally with a check…
Then you can use your session data – again you should check if its been set (isset etc…) wherever you like in your page templates, which in theory will probably be header.php again.