Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP Session variable being dropped halfway through script
    primarykey
    data
    text
    <p>I'm trying to save a session variable in one of my script and it seems to work fine for a portion of the script, however, it gets dropped in the second part of my code. I've echoed every line and can't figure out why this is happening. Also, this code was working just fine before, but ever since I switched servers, it seems to be malfunctioning. I don't think it's the session save path because the first part of the code works fine. Here is the basic outer structure of my code (I've removed all the irrelevant parts to save space):</p> <pre><code>&lt;!--raw--&gt; &lt;?php session_start(); include 'config.php'; ?&gt; &lt;html&gt; &lt;body&gt; &lt;form id="driver_record" method="post" action="&lt;?php echo htmlentities($PHP_SELF); ?&gt;"&gt; Enter Driver Number: &lt;input type="text" name="driver" /&gt; &lt;input type="submit" value="Submit" name="user_submit" /&gt; &lt;/form&gt; &lt;?php if(isset($_POST['user_submit'])) { if(username_exists($_POST['driver'])){ $ulog = $_POST['driver']; $_SESSION['user_id'] = $ulog; echo $_SESSION['user_id']; //Session echos fine here $tablename_cc = "cc_".$ulog; $tablename_db = "db_".$ulog; $tablename_misc = "misc_".$ulog; $tablename_cash = "cash_".$ulog; ?&gt; &lt;form id="expenses_update" method="post" action="&lt;?php echo htmlentities($PHP_SELF); ?&gt;"&gt; &lt;input type="submit" value="Approve" name="record_approve" /&gt; &lt;?php } } ?&gt; &lt;?php if(isset($_POST['record_approve'])) { echo $_SESSION['user_id']; //Session does not echo here $ulog = $_SESSION['user_id']; $tablename_cc = "cc_".$ulog; $tablename_db = "db_".$ulog; $tablename_misc = "misc_".$ulog; $tablename_cash = "cash_".$ulog; } //unset($_SESSION['user_id']); //session_destroy(); ?&gt; &lt;/body&gt; &lt;/html&gt; &lt;!--/raw--&gt; </code></pre> <p>EDIT: I have commented out the unset statement, and also tried putting them inside the if statement, with no change to the behavior of the code.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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