[SOLVED] Accessing PHPSESSID

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

[SOLVED] Accessing PHPSESSID

Post 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
Last edited by anjanesh on Wed Aug 03, 2005 2:26 am, edited 1 time in total.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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.
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

$_SERVER['HTTP_COOKIE'] contains the PHPSESSID part.
echo $_SERVER['HTTP_COOKIE'] will give something like
PHPSESSID=sasdasdaasasdf234
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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 =)
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post 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
    .
    .
    .
)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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..
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

I was just going to say try a print_r on $_COOKIE
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Thank you very much.
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post 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.
Last edited by anjanesh on Thu Dec 22, 2005 1:07 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I just use session_id() and let php figure it out.. since it wrote the thing.. :?
Post Reply