Page 1 of 1

[SOLVED] Accessing PHPSESSID

Posted: Wed Aug 03, 2005 1:21 am
by anjanesh
Can $_SERVER['HTTP_COOKIE'] be accessed as an array ?
Right now I have register_globals On and access the session id as $PHPSESSID.

$_SERVER['HTTP_COOKIE']['PHPSESSID'] doesnt seem to work.

Thanks

Posted: Wed Aug 03, 2005 1:58 am
by s.dot
Aren't cookies and sessions two different ways of requesting information? I can't see how they could be stored in an array like you have mentioned.

http://us3.php.net/reserved.variables mentions nothing of PHPSESSID, so it is not a part of the $_SERVER superglobal.

Posted: Wed Aug 03, 2005 2:06 am
by anjanesh
$_SERVER['HTTP_COOKIE'] contains the PHPSESSID part.
echo $_SERVER['HTTP_COOKIE'] will give something like
PHPSESSID=sasdasdaasasdf234

Posted: Wed Aug 03, 2005 2:10 am
by s.dot
Hmm reading the manual I don't see http_cookie included in $_SERVER. Then again, you are ranked a 'master' so I will believe what you say! Thanks for the information... and sorry I couldn't help you out =)

Posted: Wed Aug 03, 2005 2:14 am
by anjanesh
scrotaye wrote: Then again, you are ranked a 'master' so I will believe what you say!
Im a master in Posting in forums - not yet in PHP though.

Code: Select all

echo '<pre>';print_r($_SERVER);echo '</pre>';

Code: Select all

Array
(

    .
    .
    .
    [HTTP_COOKIE] => PHPSESSID=f9visti34oagm4kusv5rilc957
    .
    .
    .
)

Posted: Wed Aug 03, 2005 2:16 am
by feyd
$_SERVER['HTTP_COOKIE'] is the raw cookie string that is sent by the browser. $_COOKIE is the exploded out version of that. parse_str() can perform this explosion..

Posted: Wed Aug 03, 2005 2:17 am
by s.dot
I was just going to say try a print_r on $_COOKIE

Posted: Wed Aug 03, 2005 2:25 am
by anjanesh
Thank you very much.

Posted: Wed Aug 03, 2005 10:00 pm
by anjanesh
I last q.

What if cookies are not enabled ? Then it'll automatically go via URL right ?
So it'll be $_GET['PHPSESSID'] instead of $_COOKIE['PHPSESSID'].

In that wouldnt $PHPSESSID be easier to access ? register_globals On only for this.

Posted: Wed Aug 03, 2005 10:07 pm
by feyd
I just use session_id() and let php figure it out.. since it wrote the thing.. :?