Note that there are some explanatory texts on larger screens.

plurals
  1. PONew & Improved PHP Session Redirect Problem
    primarykey
    data
    text
    <p>I'm working on a multi-page form. Here's the outline of its function:</p> <p><strong>Part One:</strong> Collect Form Input Fields -> Sends user to transfer.php using POST method</p> <p><strong>Part Two:</strong> transfer.php | Validates that nothing is empty -> Stores $_POST variables into a $_SESSION -> Redirects user to next part of the form.</p> <p><strong>Part Three:</strong> Second Part of Form | Maintains the session from the first form -> Adds new variables to the session -> Preps for everything to get emailed</p> <p>I've been reading how using header( location: ) etc drops session information. The solution people seem to find is to validate the form on page, then direct the user using the action field of the form.</p> <hr> <p><strong>The problem I'm having:</strong> Where the form redirects is based on the input from the form. There are actually 8 potential forms that the user could be forwarded to depending on what they input during the first form.</p> <blockquote> <p>I've tried SID techniques and the SESSION variables show up as registered, but they all display &amp;NULL.</p> </blockquote> <p><strong>Question:</strong> How can I get the session variables to display on the next page?</p> <hr> <p>Here's the code I have so far:</p> <p>Part 1: the form</p> <pre><code>&lt;form method="POST" action="transfer.php"&gt; ... all my form elements with proper names &lt;/form&gt; </code></pre> <p>Part 2: transfer.php</p> <pre><code>&lt;?php session_start(); $_SESSION = $_POST; // project_type would store an url for the corresponding 2nd part of the form $redirect = $_SESSION['project_type']; $redirect .= "?phpSESSID=".session_id(); header("Location: $redirect"); exit(); ?&gt; </code></pre> <p>Part 3: the next form</p> <pre><code>&lt;?php // initialize a session session_start(); echo "&lt;p&gt;Session ID: " . session_id() . "&lt;/p&gt;"; echo "&lt;p&gt;Vardump Set Off Page: "; var_dump($_SESSION); echo "&lt;/p&gt;"; ?&gt; &lt;form method="...... the rest of the form etc </code></pre> <hr> <p>I know that the post is making it to transfer.php correctly. I know that the content of $_POST is being copied to $_SESSION correctly. I know that somewhere during the redirect, the session variables are being set to &amp;NULL</p> <p>Here's what the var_dump looks like after the user gets redirected to the 2nd part of the form.</p> <pre><code>array(18) { ["project_type"]=&gt; &amp;NULL ["project_timeframe"]=&gt; &amp;NULL ["company_name"]=&gt; &amp;NULL ["company_address"]=&gt; &amp;NULL ["company_city"]=&gt; &amp;NULL ["company_state"]=&gt; &amp;NULL ["company_zipcode"]=&gt; &amp;NULL ["company_phone"]=&gt; &amp;NULL ["company_website"]=&gt; &amp;NULL ["contact_name"]=&gt; &amp;NULL ["contact_title"]=&gt; &amp;NULL ["contact_email"]=&gt; &amp;NULL ["contact_phone"]=&gt; &amp;NULL ["contact_primary_phone_type"]=&gt; &amp;NULL ["contact_phone_alt"]=&gt; &amp;NULL ["contact_alternate_phone_type"]=&gt; &amp;NULL ["contact_preferences"]=&gt; &amp;NULL ["contact_preferences_additional"]=&gt; &amp;NULL } </code></pre>
    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.
    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