HuuD Posted September 25, 2017 Share Posted September 25, 2017 (edited) Hi All,I have this issue where the PHP session stored in one page is not received in the new page, I have set the session_start(); at the very top of all the pages the page and funnily there is no error but the data does not show on the new page, please find the code below as Im not able to understand whats going wrong here, Thanks. I CAN ADD THE FULL CODE, BUT ITS TOO LENGHTY. Also is there a simple PHP debugger as the xDebug does not work I have tried several methods...The error I receive : Notice: Undefined index: sesName in D:\Softwares\Xampp\htdocs\book\booking.php on line 3 But when I check the the echo of the session in the page that priginated, there is data, also note that all the 3 codes below are from different pages.Session data sending page : while ($row = mysqli_fetch_assoc($result)) { $dbemail = $row["email"]; $dbpass = $row["password"]; } if(($lemail == $dbemail) && ($lpass == password_verify($lpass, $dbpass))) { $_SESSION['sesName'] = $dbemail; echo $_SESSION['sesName']; header("Location:booking.php"); Session data receiving page : <?php session_start(); echo $_SESSION['sesName']; ?> <!DOCTYPE html> <html lang="en"> <body id="admin"> <head> <link href="css/bootstrap.min.css" rel="stylesheet"> <link href="css/datepicker3.css" rel="stylesheet"> <link href="css/styles.css" rel="stylesheet"> </head> <body> <div class="row"> <div class="col-xs-10 col-xs-offset-1 col-sm-8 col-sm-offset-2 col-md-4 col-md-offset-4"> <div class="login-panel panel panel-default"> <div class="panel-heading"><p class="text-center">CABSONLINE</p></div> <div class="panel-heading"> <?php if (empty($_SESSION['sesName'])) { echo '<span class="label label-danger center-block">YOU ARE NOT LOGGED IN, REDIRECTING TO LOGIN PAGE..</span></h3>'; echo "<meta http-equiv='refresh' content='4;url=login.php'>"; } else { echo '<h5>' . $_SESSION['sesName'] . ' IS LOGGED IN, FILL IN THE DETAILS AND BOOK A CAB</h5>'; } ?>Page destroying the session : if (isset($_POST['logout'])) { session_unset(); session_destroy(); header("location:index.html"); Edited September 25, 2017 by HuuD Quote Link to comment Share on other sites More sharing options...
Barand Posted September 25, 2017 Share Posted September 25, 2017 Despite what I told you in a previous post, you are still using password_verify incorrectly, so that code does not execute and the session variable does not get set. RTFM password_verify If you are just going to ignore replies then you are wasting everyone's time. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted September 25, 2017 Share Posted September 25, 2017 Plus: The error message is not being interpreted correctly by you. It says "undefined index" which doesn't mean anything is wrong with your session. It simply says that you are using an index (ie, a pointer to an element of an array) that doesn't exist. This error can occur whenever you do something wrong with any array so you should get a handle on this. And the reading of other error messages. Quote Link to comment Share on other sites More sharing options...
HuuD Posted September 25, 2017 Author Share Posted September 25, 2017 Despite what I told you in a previous post, you are still using password_verify incorrectly, so that code does not execute and the session variable does not get set. RTFM password_verify If you are just going to ignore replies then you are wasting everyone's time. Hi, To verify issues, I removed password altogether and the session variable still does not get set, still the new page does not receive the session variable.. Quote Link to comment Share on other sites More sharing options...
HuuD Posted September 25, 2017 Author Share Posted September 25, 2017 Plus: The error message is not being interpreted correctly by you. It says "undefined index" which doesn't mean anything is wrong with your session. It simply says that you are using an index (ie, a pointer to an element of an array) that doesn't exist. This error can occur whenever you do something wrong with any array so you should get a handle on this. And the reading of other error messages. Apologies, Im not a hard programmer, so if you could explain in some simple english... The session variable value echoes fine so storage is not an issue, but when I try to echo it on the next page it shows this error, I did a lot of reading followed accordingly but still the issue persists... Should I post the whole code ? Quote Link to comment Share on other sites More sharing options...
HuuD Posted September 25, 2017 Author Share Posted September 25, 2017 Apologies, Im not a hard programmer, so if you could explain in some simple english... The session variable value echoes fine so storage is not an issue, but when I try to echo it on the next page it shows this error, I did a lot of reading followed accordingly but still the issue persists... Should I post the whole code ? This is what is happening now... The login and registration pages are linked to a single booking page. When I login the session variable is NOT received by the booking page but when I register the variable session is received by the booking page and shows user logged. Thank.. Quote Link to comment Share on other sites More sharing options...
HuuD Posted September 25, 2017 Author Share Posted September 25, 2017 (edited) This is what is happening now... The login and registration pages are linked to a single booking page. When I login the session variable is NOT received by the booking page but when I register the variable session is received by the booking page and shows user logged. Thank.. This issue is resolved, I had an If condition on session in login page which I removed and its working on both pages now.. Edited September 25, 2017 by HuuD Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.