Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sessions in header redirects

Status
Not open for further replies.

MarlaJ

Programmer
Jul 21, 2003
20
US
I'm having problems passing my session variables in a redirect and my understanding is I don't need to use session_register in this instance. Below is my most recent version of the code that sets my variables and redirects to index.php. I am attempting to pass the SID (in this case it's called PHPSESSID) in the URL because I can't seem to get the browser to recognize the session has already been set without the SID. It appears to be succesful from the looks of the url on redirect but I don't know how to retrieve my session variables after the redirect occurs. I do have session_start() on the index.php which is where I redirect to. Any help would be appreciated and if I'm doing this completely wrong please tell me. I've only been using PHP for a week so I'm clueless.

{
session_start();
$_SESSION['userid_s'] = $id;
$_SESSION['fname_s'] = $fname;
$_SESSION['lname_s'] = $lname;
$_SESSION['email_s'] = $email;
$_SESSION['tt_s'] = $tt;
$_SESSION['news_s'] = $news;
$_SESSION['dm_s'] = $dm;
$_SESSION['calendar_s'] = $calendar;
$_SESSION['whitepapers_s'] = $whitepapers;
$_SESSION['subscriptions_s'] = $subscriptions;
$_SESSION['articles_s'] = $articles;
$_SESSION['login_s']= "yes";
if(isset($_SESSION['userid_s']))
{
header("Location: index.php?SID=$PHPSESSID");
}
else
{
echo "Sorry, the session couldn't be set. Please log back in and check rememberme.";
}
}
Below is my PHP.ini file, which I've been told was the default install for PHP 4.0.
[Session]
session.save_handler = files
session.save_path = /tmp
session.use_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.cookie_path = /
session.cookie_domain =
session.serialize_handler = php
session.gc_probability = 1
session.gc_maxlifetime = 1440
session.referer_check =
session.entropy_length = 0
session.entropy_file =
session.cache_limiter = nocache
session.cache_expire = 180
session.use_trans_sid = 1

So....am I offbase on how to do this and if not, what's my next step in retrieving my variables on index.php? Please help! My only PHP book is aweful :)
 
Are you running PHP with IIS? If so, you are running afoul of a known IIS issue, that it won't send cookies on a redirect. Unless you are sending the session ID through a URL, PHP's session handling system uses a cookie to store the session ID.

One workaround is instead of outputting a Location HTTP header, to redirect the browser through the use of an HTML META tag or through client-side JavaScript.



I'm not sure about your comment of not knowing how to access session variables after the redirection. If you have session_start(), then $_SESSION will be automagically initialized with all the session variables.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
I'm running on an Apache server but I am sending the SID through the URL via this line in my code:

header("Location: index.php?SID=$PHPSESSID");

You did answer my question about how to access my variables after the redirect though even though I confused you ;) Thanks! Off to play...

 
Alternatively you could just include the file, via:

include("blahblah.inc");
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top