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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP Sessions lost after Redirect

Status
Not open for further replies.

power97

Programmer
Sep 17, 2003
67
CA
Hi,
I have a simple login page that I developed for a client that worked great locally but when I moved it to thier IIS servers it stopped working. The problem is that it doesn't seem to retain the session values after I do a redirect ( header("location ....")). Are there any work arounds for this ? I have seen some people suggestion mixing in some javascript to do the redirect but I'd prefer to keep it server side.

Thanks


 
That's because IIS will not send cookies on a redirect. It has to do with a bizarre interpretation of the HTTP spec that is unique to Mi[$cent;]ro$oft.

The only workaround is to set the cookie then send an HTML page with a <META> tag.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
i use IIS and it keeps the sessions for me

you need to have session_start(); on the pages that you want the sessions to carry on

Code:
//db query

while($r = mysql_fetch_array($query)){
     $user = $r["userfield"];
     $_SESSION['username'] = $user;
}

hope it helps


Martin

Computing help and info:

 
martinb:
If the script that issues the original session cookie (not reusing a session cookie from an earlier run of a script on the site) also uses the "Location:" header, the session cookie will not be created on the client machine. The next script on your site will not have the session variables available.

The problem with IIS, cookies, and the "Location:" header http://support.microsoft.com:80/support/kb/articles/q176/1/13.asp&NoWebContent=1]is well documented[/url].



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
power97:
The solution is to quit using IIS. But that's opinion, not fact.

But if you reread my original post in this thread, I think you'll find I did suggest a workaround. Look for the string "META".

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top