note 68710 added to function.session-start
| From: | core58 at mail dot ru | Date: | Tue, 08 Aug 2006 13:36:52 +0000 |
| Subject: | note 68710 added to function.session-start | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-115651@lists.php.net to get a copy of this message | ||
when you're using session trans sid ENABLED, and you perform redirect such as Header(
"Location..." ), redirected client will SURELY loose his session.
to avoid this, you can use a modified version of redirect function, like this:
<?php
function Redirect302( $location )
{
$sname = session_name();
$sid = session_id();
if( strlen( $sid ) < 1 )
{
Header( $location );
return;
}
if( isset( $_COOKIE[ $sname ] ) || strpos( $location, $sname."=".$sid ) !== false )
{
Header( $location );
return;
}
else
{
if( strpos( $location, "?" ) > 0 )
$separator = "&";
else
$separator = "?";
$fixed = $location . $separator . $sname."=".$sid;
Header( $fixed );
return;
}
}
?>
expamle:
Redirect302( "Location: /YourPage/index.php" );
the function performs common redirect if no session is active, and appends session
"name=sid" to query string when session is already started, like PHP parser does when
outputting your page.
hope, you'll find it useful.
yours:)
----
Server IP: 66.163.161.117
Probable Submitter: 213.184.229.145
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.session-start.php
Edit -- https://master.php.net/note/edit/68710
Del: integrated -- https://master.php.net/note/delete/68710/integrated
Del: useless -- https://master.php.net/note/delete/68710/useless
Del: bad code -- https://master.php.net/note/delete/68710/bad+code
Del: spam -- https://master.php.net/note/delete/68710/spam
Del: non-english -- https://master.php.net/note/delete/68710/non-english
Del: in docs -- https://master.php.net/note/delete/68710/in+docs
Del: other reasons-- https://master.php.net/note/delete/68710
Reject -- https://master.php.net/note/reject/68710
Search -- https://master.php.net/manage/user-notes.php