note 103526 modified in function.header by danbrown
| From: | danbrown@php.net | Date: | Mon, 18 Apr 2011 15:50:16 +0000 |
| Subject: | note 103526 modified in function.header by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-178947@lists.php.net to get a copy of this message | ||
When using header(Location:), if you have the same site that you use which has different URIs, for
example:
www.example.com/a/mysite
www.example.net
you must remain consistent in how you reference it, or $_SESSION[] contents will be lost.
An example would be a user enters www.example.com/a/mysite, then based on some decision they make,
you want to header(Location:) them to another page. If you header(Location: http://www.example.net/page.php), $_SESSION[] will be
lost.
I solved this by forwarding them to a particular URI before I start saving $_SESSION[] variables:
<?php
if (strpos($_SERVER['REQUEST_URI'], "/a/mysite/") !== false)
header('Location: http://www.example.net');
?>
--was--
When using header(Location:), if you have the same site that you use which has different URIs, for
example:
www.mainserver.com/a/mysite
www.mysite.com
you must remain consistent in how you reference it, or $_SESSION[] contents will be lost.
An example would be a user enters www.mainserver.com/a/mysite, then based on some decision they
make, you want to header(Location:) them to another page. If you header(Location: http://www.mysite.com/page.php), $_SESSION[] will be lost.
I solved this by forwarding them to a particular URI before I start saving $_SESSION[] variables:
<?php
if (strpos($_SERVER['REQUEST_URI'], "/a/mysite/") !== false)
header('Location: http://www.mysite.com');
?>
http://php.net/manual/en/function.header.php