Note that there are some explanatory texts on larger screens.

plurals
  1. POphp: session disappears after page navigation
    primarykey
    data
    text
    <p>I've read all the posts I could find about this issue, but, to date, none of the solutions have worked for me. Obviously, I'm overlooking something important. I also don't know how to debug sessions. I read one article, <a href="http://css.dzone.com/news/php-session-debugging" rel="nofollow">PHP session Debugging</a>, but it was over my head.</p> <p>So, much like the other issues, when I navigate to another page in my app, whether through a link or a form submit, my session disappears. I have no idea why my session vanishes. If someone has the time to help me investigate, it would be greatly appreciated.</p> <p>These are my php.ini settings</p> <pre><code>; Name of the session (used as cookie name). session.name = PHPSESSID ; The path for which the cookie is valid. session.cookie_path = / </code></pre> <p>This is the first view to display</p> <pre><code>&lt;?php session_start(); if (!isset($_SESSION['session_id'])) { $_SESSION['session_id'] = session_id(); } if (!isset($_SESSION['invoices'])) { $_SESSION['invoices'] = $invoices; } if (isset($_SESSION['session_id'])) { print_r($_SESSION['session_id'] . " in invoiceList.&lt;br /&gt;"); } else { echo 'No session ID set in invoiceList &lt;br /&gt;'; } ?&gt; &lt;div&gt; &lt;table&gt; &lt;tr&gt; &lt;th&gt;Customer Name&lt;/th&gt; &lt;th&gt;Invoice Date&lt;/th&gt; &lt;th&gt;Invoice Number&lt;/th&gt; &lt;/tr&gt; &lt;tr&gt; &lt;?php include_once 'form/editInvoice.php'; if (isset($invoices)) { foreach ($invoices as $invoice) { ?&gt; &lt;tr&gt; &lt;td&gt;&lt;?php echo $invoice['customer_name'] ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $invoice['invoice_date'] ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $invoice['invoice_number'] ?&gt;&lt;/td&gt; &lt;td&gt;&lt;a href='&lt;?php echo $_SERVER['SCRIPT_NAME']; ?&gt;/retrieve?class=InvoiceLineItems&amp;amp;id=&lt;?php echo $invoice['invoice_id']; ?&gt;'&gt;&lt;?php echo $invoice['invoice_id']; ?&gt;&lt;/a&gt;&lt;/td&gt; &lt;/tr&gt; &lt;?php } } else { echo 'No invoices retrieved.'; } ?&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/div&gt; </code></pre> <p>Here is the included form:</p> <pre><code>&lt;?php session_start(); if (isset($_SESSION['session_id'])) { print_r($_SESSION['session_id'] . "in editForm&lt;br /&gt;"); } else { echo 'No session ID set in editForm &lt;br /&gt;'; } if (!$_POST) { ?&gt; &lt;form action="&lt;?php $_SERVER['PHP_SELF'] ?&gt;" method="post"&gt; &lt;fieldset&gt; &lt;legend&gt;Enter Updated PO Number&lt;/legend&gt; &lt;li&gt;PO Number: &lt;input type="text" name="po_number"/&gt;&lt;/li&gt; &lt;/fieldset&gt; &lt;input type="submit" value="Submit" /&gt; &lt;input type="button" onclick="alert('Changes Canceled.')" value="Cancel"/&gt; &lt;/form&gt; &lt;?php } ?&gt; </code></pre> <p>And finally, the detail page for when the user clicks a link in the main page.</p> <pre><code>&lt;?php session_start(); if (isset($_SESSION['session_id'])) { print_r($_SESSION['session_id'] . "&lt;br /&gt;"); } else { echo 'No session ID set invoice&lt;br /&gt;'; } ?&gt; &lt;h1&gt;Invoice Detail&lt;/h1&gt; &lt;div&gt; &lt;?php foreach ($partnerInfo as $info) { switch ($info['role_indicator']) { case 'remit_to': ?&gt; &lt;div id="remit"&gt; &lt;ul&gt; &lt;li&gt;PLEASE REMIT TO:&lt;/li&gt; &lt;li&gt;&lt;?php echo $info['partner_name']; ?&gt;&lt;/li&gt; &lt;li&gt;&lt;?php echo $info['street_name']; ?&gt;&lt;/li&gt; &lt;li&gt;&lt;?php echo $info['city_name']; ?&gt;, &lt;?php echo $info['state']; ?&gt; &lt;?php echo $info['postal_code']; ?&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;?php break; ?&gt; &lt;?php case 'seller': ?&gt; &lt;div id = "seller" &gt; &lt;ul&gt; &lt;li&gt;Service Site:&lt;/li&gt; &lt;li&gt;&lt;?php echo $info['partner_name']; ?&gt;&lt;/li&gt; &lt;?php if ($info['partner_aux_info'] !== NULL) { ?&gt;&lt;li&gt;&lt;?php echo $info['partner_aux_info']; ?&gt; &lt;?php } ?&gt; &lt;/li&gt; &lt;li&gt;&lt;?php echo $info['street_name']; ?&gt;&lt;/li&gt; &lt;li&gt;&lt;?php echo $info['city_name']; ?&gt;, &lt;?php echo $info['state']; ?&gt; &lt;?php echo $info['postal_code']; ?&gt;&lt;/li&gt; &lt;li&gt;(405)677-0221&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;?php break; ?&gt; &lt;?php case 'sold_to': ?&gt; &lt;div id="buyer"&gt; &lt;ul&gt; &lt;li&gt;Bill To: &lt;/li&gt; &lt;li&gt;&lt;?php echo $info['partner_name']; ?&gt;&lt;/li&gt; &lt;li&gt;&lt;?php echo $info['street_name']; ?&gt;&lt;/li&gt; &lt;?php if ($info['suite_info'] !== NULL) { ?&gt;&lt;li&gt;&lt;?php echo $info['suite_info']; ?&gt; &lt;?php } ?&gt; &lt;/li&gt; &lt;li&gt;&lt;?php echo $info['city_name']; ?&gt;, &lt;?php echo $info['state']; ?&gt; &lt;?php echo $info['postal_code']; ?&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;?php break; ?&gt; &lt;?php } } ?&gt; &lt;h1&gt;Line Items&lt;/h1&gt; &lt;table&gt; &lt;th&gt;PO Number&lt;/th&gt; &lt;th&gt;PO Issued Date&lt;/th&gt; &lt;th&gt;Description&lt;/th&gt; &lt;th&gt;Service Start Date&lt;/th&gt; &lt;th&gt;Service End Date&lt;/th&gt; &lt;th&gt;Shipped Date&lt;/th&gt; &lt;?php foreach ($invoiceLineItems as $lineItem) { ?&gt; &lt;tr&gt; &lt;td&gt;&lt;?php echo $lineItem['po_number']; ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $lineItem['po_issued_date']; ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $lineItem['line_item_name']; ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $lineItem['service_period_start']; ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $lineItem['service_period_end']; ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $lineItem['request_for_delivery']; ?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;?php } ?&gt; &lt;/table&gt; &lt;/div&gt; </code></pre> <p>Edit: I've removed the session checks and updated the code sample. I've added session_start() before my <code>&lt;head&gt;</code> tag in index.php. I've verified that I can write to the session temp folder. </p> <p>When i execute this code in my controller to update the invoices with the new PO number, I reach the model's function, but the session is gone.</p> <pre><code>//If form is posted, update line items with PO number and date. if (isset($_POST['po_number'])) { $this-&gt;invoice-&gt;update(); } </code></pre> <p>By the time I reach the session variable assignment, I have no session data:</p> <p>public function update() {</p> <pre><code>$con = $this-&gt;_getLocalConn(); $invoices = $_SESSION['invoices']; try { $sqlUpdate = $con-&gt;prepare("UPDATE invoices SET po_number = ?, po_issued_date = ? WHERE invoice_id = ?"); foreach ($invoices as $record) { $sqlUpdate-&gt;execute(array( $_POST['po_number'], getdate(), $record['invoice_id'] )); } } catch (PDOException $e) { print $e-&gt;getMessage(); } //get the PO number being used to update the records //perform db update where po_number = input //notify user of success and display updated records. </code></pre> <p>}</p>
    singulars
    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