Jump to content

Cannot read PHP session


itpvision

Recommended Posts

Hello

I have built 21 web sites, when I changed hosting, the PHP log in failed, due to failure to read the php session

 

to the log in pahe:

@session_start();

if(isset($_POST['user']) && $_POST['user'] != '' && isset($_POST['pass']) && $_POST['pass'] != '')

{

$pass = mysql_escape_string(addslashes($_POST['pass']));

$user = mysql_escape_string(addslashes($_POST['user']));

$query = "select * from table where name = '$user' AND pass = password('$pass') ";

$query2 = mysql_query($query);

if(mysql_num_rows($query2) < 1)

{

header("location:login.php");

exit;

}

else

{

$_SESSION['user'] = $user;

$_SESSION['keylock'] = "abcd";

header("location:privatepage.php");

 

}

}

else

{

 

header("location:$referer");

exit;

 

}

 

I reach the private page, here the session cannot be read , and I am redirected to the forbidden page

@session_start();

if(isset($_SESSION['keylock']) && $_SESSION['keylock'] == "abcd")

{

$user = $_SESSION['user'] ;

$display = "<br><div align = 'center'> Welcome <b> $user </b>

 

<a href = 'signout.php'> <b> » SIGN OUT </b> </a>

</div> <br> ";

require_once('header.php');

echo $display;

}

else

{

header("location:forbiden.php");

exit;

}

The second case is true

I tried to comment the redirection, and

wrote a varaiable

$d = $_SESSION['keylock'] ;

echo " session $d ";

I only get an output session, the session cannot be read

Link to comment
https://forums.phpfreaks.com/topic/155356-cannot-read-php-session/
Share on other sites

Remove the @ from in front of the session_start() statement as that will hide any errors that would tell you why it is not working and add the following two debugging lines immediately after your first <?php tag -

 

ini_set ("display_errors", "1");
error_reporting(E_ALL);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.