Page 1 of 1
sessions not working with header
Posted: Mon Apr 17, 2006 1:52 pm
by shiznatix
Yes I posted this at the end of my last post but I think this deserves its own thread since its entirly different subject. I have this quick code snip:
Code: Select all
<?php
if (!empty($_GET['lang']))
{
$langs = array('eng', 'est', 'fin', 'rus');
$language = strtolower($_GET['lang']);
$language = trim($language);
if (in_array($language, $langs))
{
$_SESSION['lang'] = $language;
header("Location: ".$_SESSION['last_page']);
die();
}
}
if (!empty($_SERVER['HTTP_REFERER']))
$_SESSION['last_page'] = $_SERVER['HTTP_REFERER'];
else
$_SESSION['last_page'] = $GLOBALS['sroot'];
?>
now when I header it the new value for $_SESSION['lang'] does not stay but if i don't header to the new location then it works fine (but i need the header!). Any ideas?
Posted: Mon Apr 17, 2006 1:56 pm
by John Cartwright
the documentation for
session_write_close() explains it better than I can
basically, call
session_write_close() before you send headers
Posted: Mon Apr 17, 2006 2:01 pm
by shiznatix
Code: Select all
if (!empty($_GET['lang']))
{
$langs = array('eng', 'est', 'fin', 'rus');
$language = strtolower($_GET['lang']);
$language = trim($language);
if (in_array($language, $langs))
{
$_SESSION['lang'] = $language;
session_write_close();
header("Location: ".$_SESSION['last_page']);
die();
}
}
does not work

Posted: Mon Apr 17, 2006 2:03 pm
by John Cartwright
Code: Select all
$last_page = $_SESSION['last_page'];
session_write_close();
header("Location: ".$last_page);
shot in the dark, I havn't had experience with this function really..
Posted: Mon Apr 17, 2006 2:08 pm
by shiznatix
no luck. anyone else? version info:
PHP Version 5.0.5-2ubuntu1.2
Posted: Mon Apr 17, 2006 2:12 pm
by feyd
Start the session prior to this redirection page being hit.
Posted: Mon Apr 17, 2006 2:16 pm
by shiznatix
feyd wrote:Start the session prior to this redirection page being hit.
say again? the session has already been started. this is confirmed when I put another session start above the setting of the new session[lang] as it gives me the error stuff. or did you mean somthing else?
Posted: Mon Apr 17, 2006 2:50 pm
by feyd
I mean start the session on a previous page. There's no need to write out session headers (overall) after they have already been started previously.
Posted: Mon Apr 17, 2006 2:54 pm
by shiznatix
...i am? are you telling me to do somthing different? sessions have been started ahhhh!
Posted: Mon Apr 17, 2006 3:45 pm
by Oren
Two questions:
1. Did you use session_start() at all?
2 Which firewall do you have?
Posted: Mon Apr 17, 2006 4:26 pm
by shiznatix
yes, the session has already been started. this page is included in my header file that has my session start.
no, i don't have a firewall setup at all. no firewall.
Posted: Mon Apr 17, 2006 4:32 pm
by printf
Can we see more of the script! Where is this being set, $_SESSION['last_page']. Also you say it not working, what exactly is happening?
printf!
Posted: Mon Apr 17, 2006 4:43 pm
by shiznatix
wait. never mind. forget i exist. please delete this thread.
Posted: Mon Apr 17, 2006 4:57 pm
by Oren
shiznatix wrote:no, i don't have a firewall setup at all. no firewall.
You really don't have a firewall?!
Posted: Mon Apr 17, 2006 4:58 pm
by shiznatix
Oren wrote:shiznatix wrote:no, i don't have a firewall setup at all. no firewall.
You really don't have a firewall?!
i like to live life on the edge.