Page 1 of 1
[SOLVED...]lost sessions after redirect
Posted: Tue Apr 18, 2006 7:49 am
by rubberjohn
i've just been looking at why my session data is not being retained after a redirect. however session info has been retained in other parts of my site after a redirect, why is it now being lost?
it is happening in the course of three pages
search.php to search_process.php - sessions passed ok
search_process.php to search_results.php - no sessions passed
any ideas??
thanks
rj
Posted: Tue Apr 18, 2006 7:53 am
by Oren
Can we see the code?
Posted: Tue Apr 18, 2006 8:10 am
by rubberjohn
the whole code is too long but the relevant bits are
on the search page
Code: Select all
if(isset($_POST['search'])){
if(isset($_SESSION['my_search_box'])){
header('Location: http://www.merseysideemploymentlaw.co.u ... ocess.php');
exit;
}else{
echo "Please choose a tag before trying to search";
}
}
$_SESSION['my_search_box'] can then be access in search_process.php, also in search_process.php i declare
Code: Select all
$_SESSION['leaf_match'] = serialize($arr_leaf_match);
$_SESSION['sub_top_match'] = serialize($arr_topic_match);
header("Location:
http://www.merseysideemploymentlaw.co.u ... s.php?.sid)");
exit;
at the end of the script.
Then when I echo $_SESSION['leaf_match'] or $_SESSION['sub_top_match'] nothing is echoed and when i use session_is_registered on them it returns FALSE. I have also tried session_write_close();
is it because the session variables in search_process.php are declared just before the redirect?
thanks rj
Posted: Tue Apr 18, 2006 8:22 am
by feyd
if session_write_close() isn't working try
Code: Select all
$_SESSION['leaf_match'] = serialize($arr_leaf_match);
$_SESSION['sub_top_match'] = serialize($arr_topic_match);
header('Location: http://www.merseysideemploymentlaw.co.u ... ults.php?' . session_name() . '=' . session_id());
exit;
Posted: Tue Apr 18, 2006 8:30 am
by rubberjohn
do i need to use that sess_id to reinitiate the sessions in search_results?
if not that doesn't work either - i think it is because the session initialisation is so close to the redirect - if a create a dummy session and place it near the redirect, it doesn't work but i put it at the top of the script it does work
rj
Posted: Tue Apr 18, 2006 8:56 am
by Oren
Can you post the top of the script as well please?
Try replacing this:
Code: Select all
header("Location: http://www.merseysideemploymentlaw.co.u ... s.php?.sid)");
With this:
Code: Select all
header("Location: http://www.merseysideemploymentlaw.co.u ... ts.php?SID)");
Posted: Tue Apr 18, 2006 9:31 am
by rubberjohn
no that didn't work - what do mean top of the script?
if you mean the dummy session - at the top of search_process.php
Code: Select all
$test = array("2","4","5");
$test = serialize($test);
$_SESSION['tester'] = $test;
and when this is echoed in search_results.php it works even tho. it has been redirected.
rj
Posted: Tue Apr 18, 2006 10:12 am
by Oren
You have to call session_start() on each one of you pages before any output is sent to the browser. Did you do that?
Posted: Tue Apr 18, 2006 10:17 am
by rubberjohn
yes i have started the session.
as i said above if i place
Code: Select all
$test = array("2","4","5");
$test = serialize($test);
$_SESSION['tester'] = $test;
at the top of the search_process page - the session will echo on the search_results page but when I move it to just before the redirect, it doesnt echo.
Posted: Tue Apr 18, 2006 10:24 am
by Oren
Please post the code of each one of the 3 files you have and write above each code the name of the file, cause it's kinda stupid to work like this.
It's not one of these games where each one asks questions at his turn until someone knows the right answer

Posted: Tue Apr 18, 2006 10:44 am
by ed209
Not sure if this helps?
php.net
Posted: Tue Apr 18, 2006 11:15 am
by rubberjohn
i just went through the code bit by bit and commented out everything out - found it still didnt work and then when i uncommented everything, it worked???? - so i dont really know whats going on here there must be a bug somewhere which ill have to find but thanks for your help
rj
Posted: Tue Apr 18, 2006 2:12 pm
by feyd
maybe it was a caching problem?