Re: Cookies and Sessions: What's the Best Recipe?
| From: | Monty | Date: | Tue, 03 Jun 2003 15:44:20 +0000 |
| Subject: | Re: Cookies and Sessions: What's the Best Recipe? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-149989@lists.php.net to get a copy of this message | ||
> Guys, that's exactly what the SID predefined constant is for -- it's defined
> only when a session is active, and it has the value
> <sessionname>=<sessionid> (e.g. PHPSESSID=1afd764ecb938274) if and only if
> the session id was passed in the URL -- otherwise it contains the empty
> string. So you can safely do:
>
> header("Location: {$location}?".SID);
The SID constant var is a good idea! I didn't realize this existed. Taking
what Justin originally suggested, I've now modified the myHeader() function
to only append the SID if it exists (else, it returns the $location var as
it was passed). It also checks to see whether there is a ? in the $location
var. If so, it will append the SID using a &, otherwise it will append the
SID with a ?.
I haven't tested this yet, but, if anyone has any other suggestions or
recommendations, please post them.
function myHeader($location) {
if (SID) {
if (strstr($location, '?')) {
header("Location: {$location}&".SID);
} else {
header("Location: {$location}?".SID);
}
} else {
return $location;
}
return;
}
Monty