PHP Sessions


I need help on Sessions in PHP.

while using sessions in my login script in localhost it works great. But the same when i upload in the webhost its not working. I cant figure out why, Please help me on this…


if (!empty($_SESSION[“user”])
{echo “welcome user”;
echo “Logout”;

echo “Welcome Guest !”;
echo " | ";

echo “Login”;
echo " | ";
echo “Register”;


and login action page :

[php]$checklogin = mysql_query(“SELECT * FROM users WHERE Username = '”.$username."’ AND Password = ‘".$password."’");
//echo $checklogin;
if(mysql_num_rows($checklogin) == 1)
echo “Login Success”;
$_SESSION[“user”]= $username;
$_SESSION[“snicyloggedin”] = 1;
header(“location: posts/index.php”);

				header("location: login1.php?err=Username or Password is Incorrect");

I haven’t seen any session_start on login.php?
This might be happening due to output buffer. Your webhost may have turned off the output buffer, If you have access to the php.ini file on your web-server, you can turn it on or you can do the following.

right after the starting PHP tag and add
right before the closing PHP in your login.php page.

I have also noticed a missing parentheses on secuedpage, change your code to following.
[php]if (!empty($_SESSION[“user”])) [/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service