In the login form of one of my PHP project. After all validation I set $_SESSION['username'] = $username
(where $username
value is coming from db_username
of that user and when I write echo $username;
it prints the correct value).
Suppose $username
is "Admin" so $_SESSION['username'] = 'Admin'
.
After successfully login, the page reloads automatically, and here the issue arise. As I'm already logged in, it must show My Profile menu instead of Login menu, but it shows Login menu. So I use echo $_SESSION['username']
which prints blank value, while it should print "Admin".
This works fine in my local server (XAMPP, PHP version: 7.0.9), but the problem occurs when I upload those code in live server (PHP version: 5.6.30).
PHP Session is running. As I use the following code to check:
if( !session_start() ) {
session_start();
} else {
echo 'Session is started';
}
Can anyone help me to fix this problem? Thanks in advance.