PHP Sessions

Hi,

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…

securedpage:

[php]<?php
session_start();
if (!empty($_SESSION[“user”])
{echo “welcome user”;
echo “Logout”;
}
else
{

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

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

}
?>[/php]

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”);

				}
				else
				{
				header("location: login1.php?err=Username or Password is Incorrect");
				}[/php]

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.

add
[php]ob_start();[/php]
right after the starting PHP tag and add
[php]ob_end_flush();[/php]
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