In one page of our site, I have this code:
$_SESSION['returnURL'] = "/store/checkout/onepage";
and further down, this button control:
<button type="button" title="Register Today" class="button" onclick="window.location = '/register/';" id="BecomeMember"><span><span>Become a Member Today</span></span></button>
Now, in the register template, I have this code:
<input type="hidden" name="returnURL" id="returnURL" value="<?php if(isset($_SESSION['returnURL'])) { echo $_SESSION['returnURL']; } else { echo '/'; } ?>" />
But it only shows the value as /.
What could be going on that is causing this?
first.php
<?php
session_start();
$_SESSION['returnURL'] = "/store/checkout/onepage";
echo '<a href="second.php">Pass session to another page</a>';
?>
second.php
<?php
session_start();
echo 'returnURL = ' . $_SESSION['returnURL'];
?>
So you need to write session_start()
in both your files
To solve this problem, you will need to:
1) Ensure that session_start()
is called at the beginning of the script, before anything else.
2) Nothing is unsetting $_SESSION
or $_SESSION['returnURL']
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With