Getting PHP variable from page to another
Not sure what I am doing wrong here ...
On one page, I start a session close to the beginning of the start of the code, for example:
session_name('raprec');
session_start();
And then I collect session variables throughout the code by assigning session variables to PHP variables that I need to reuse like this:
$_SESSION['item_type'] = $item_type;
$_SESSION['special_rope_fields'] = $special_rope_fields;
$_SESSION['zoom_obj'] = $zoom_obj;
On the second page, where I need the elements, I call the session again:
session_start();
session_name('raprec');
Then I will try to use them on this second page as shown below:
$special_rope_fields = $_SESSION['special_rope_fields'];
$item_type = $_SESSION['item_type'];
$zoom_obj = $_SESSION['zoom_obj'];
But that doesn't work ...
I'm trying to see if something is like this:
print_r($_SESSION['special_rope_fields']);
print_r($_SESSION['item_type']);
print_r($_SESSION['zoom_obj']);
But nothing appears.
What am I doing wrong here? How can I pass these variables from one page to another? Is there an easier way perhaps?
source to share
I tested your code on my server and I had the same results as yours, nothing ... then, on , I changed: second page
session_start();
session_name('raprec');
to
session_name('raprec');
session_start();
The session is raprec
now working as intended.
The function
session_name()
will have no significant effect if you setsession.auto_start
beforetrue
tophp.ini
source to share
per this documentation, http://php.net/manual/en/function.session-name.php you need to call session_start after calling session_name.
edit @maztch sorry i updated. Thanks for pointing that out. I meant it backwards, but this is what I meant, I was trying to point out that the document has a specific order ... thanks. and in this case it is not the answer to everything, because in the end it does not solve the question. oops ..
source to share