I have the following PHP code:
session_start();
$zip = $_GET['zip'];
$_SESSION['zip'] = $zip;
echo $_SESSION['zip']; //output is 98121, or whatever value I assigned
Then when I go to the next page using the following code:
<div id="heading"><h2>What day and time would you like your stuff picked up?</h2></div>
<div class="nav_buttons">
<button class="previous">Previous</button>
<button class="next">Next</button>
</div><!--end nav_buttons-->
<form action="/wordpress/junk-details" method="post">
<?php for($j = 0; $j < 7; $j++): ?>
<div class="date_container" id="date_container_<?php echo $j;?>" >
<?php for($i = 0; $i < 7; $i++): ?>
<div class="day">
<div class="date" id="">
</div><!--end date-->
</div><!--end day-->
<?php endfor; ?>
</div><!--end date_container-->
<?php endfor; ?>
<div class="nav_buttons">
<button class="next" id="goto_step2" type="image" value="next step"><span>Next Step: Details</span></button>
</div><!--end nav_buttons-->
</form>
and I do a var_dump($_SESSION)
, the value is NULL
. I’ve checked my php.ini file, but didn’t see anything out of the ordinary. I’ve searched other similar topics on SO, but none of those have helped.
Here is a list of links I’ve tried:
PHP Session data not being saved
PHP Session Data Not Being Stored
Here are some details that might help:
I’m using PHP 5.5.3
I’m using a Mac OSX 10.9
I’m using the localhost as a server
This issue is on both Chrome and Firefox browsers
This is a wordpress site
I’m not sure what this could be. My sessions work when I use them on the back of my WordPress plugin
If you want your session variables to appear on any other page, then
session_start();
must be included inside all your pages using sessions.Footnotes:
Should you happen in the future to get the following error message:
headers already sent
, you could addob_start();
just abovesession_start();
Relevant links:
add
session_start();
on the top of your page in which you want toset session
variable orretrive session
variable value