Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP $_SESSION data returning empty
    text
    copied!<p>I have a login.php file:</p> <pre><code>&lt;?php session_start(); include('db.php'); if(isset($_POST['email']) &amp;&amp; !empty($_POST['email']) AND isset($_POST['password']) &amp;&amp; !empty($_POST['password'])){ $email = mysql_escape_string($_POST['email']); $password = mysql_escape_string($_POST['password']); $search = mysql_query("SELECT * FROM users WHERE email='".$email."' AND password='".$password."' AND active='1'") or die(mysql_error()); $match = mysql_num_rows($search); if($match &gt; 0){ $row = mysql_fetch_assoc($search); $user=$row['forename'].' '.$row['surname']; $_SESSION['username']=$user; //$msg = 'Login Complete! Thanks, '.$user.'!'; header( 'Location: page1.php' ) ; die; }else{ $msg = 'Login Failed!&lt;br /&gt; Please make sure that you enter the correct details and that you have activated your account.'; } } ?&gt; </code></pre> <p>Now, when I load page1.php I have issues. The file contains this...</p> <pre><code>&lt;?php session_start(); include('db.php'); if(isset($_SESSION['username'])){ echo 'Success, '.$_SESSION['username'].'!'; }else{ echo 'No dice!'; //header( 'Location: login.php' ) ; } ?&gt; </code></pre> <p>I ideally want it to redirect to login if there isn't a username stored. If there is, I want to allow them to view. However, I am getting "No dice!" every time, so it looks like I am not retrieving (or storing) the data correctly. What am I doing wrong?</p> <hr> <p>To be clear, the <code>else</code> shouldn't be firing as it should be referring to session data set in index.php. The redirection is not a problem.</p> <hr> <p>The problem was specific to my host who had a strange setup. On contacting them, they provided me the correct path information which I had to use <code>session_save_path</code> to set. Awarded the right answer on this basis.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload