Unable to set PHP session variable

On one page of our site I have this code:

$_SESSION['returnURL'] = "/store/checkout/onepage"; 

and further down, this control button:

 <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 this only shows the meaning as /.

What could be the reason for this?

+8
source share
8 answers

What I ended up with is sending the post variable to the page. The difference in sessions between ExpressionEngine and Magento makes this prohibitive with the use of session variables as well as cookies.

0
source

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 files

+11
source

To solve this problem, you need to:

1) Make sure session_start() is called at the beginning of the script, first of all.

2) Nothing cancels $_SESSION or $_SESSION['returnURL'] .

+2
source

I managed to get this to work as follows

 session_start(); $returnurl = "/store/checkout/onepage"; $_SESSION['returnURL'] = $returnurl; 
+1
source

I just finance, I had the same problem, sessions worked fine in firefox but not chrome, I created a test script that just created a session and then printed session_id () to see if it was created or not, after running this script I noticed that session_id () will change every time the page loads and that php throws a warning that the date / time is not set. Then i added

date_default_timezone_set ('America / Los_Angeles');

before the start of the script, this stopped the new session_id () from getting the page generated at each load and fixed the problem. (maybe it’s worth noting that my problem seems to have appeared only in my domain, and not in the top-level domain)

0
source

the server I was working on was full and thus the session did not work because there was no place to store the values. Make sure there is space on your server.

0
source

I have seen many CMS and frameworks that have a different way of handling regular sessions. If the basic two-line slot described above does not work (because it interferes with the current software), you can still use cookies for the same functionality. Remember that cookies are not deleted when the browser is closed, so you need to explicitly indicate when you need to free the variable (using unset).

 $_COOKIE["something"] = 'value'; echo $_COOKIE["something"]; unset($_COOKIE["something"]); 
0
source

The session_start () function should be the very first thing in your document. Before any HTML tags.

 session_start(); 
0
source

All Articles