itpvision Posted April 23, 2009 Share Posted April 23, 2009 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 More sharing options...
revraz Posted April 23, 2009 Share Posted April 23, 2009 Since it worked on one host and not another, first thing I would check is the php.ini and verify the session save path is valid. Link to comment https://forums.phpfreaks.com/topic/155356-cannot-read-php-session/#findComment-817339 Share on other sites More sharing options...
PFMaBiSmAd Posted April 23, 2009 Share Posted April 23, 2009 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); Link to comment https://forums.phpfreaks.com/topic/155356-cannot-read-php-session/#findComment-817350 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.