Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

session_start();echo SID; outputs a blank page on refresh?

Tags:

php

session

when I run this code for the first time

<?php
session_start();
echo SID;
?>

, I get some thing like:

PHPSESSID=9o2bhrqmln2j52caspdhholhk7

but when I refresh I get a blank page

Until I remove the PHPSESSION cookie and start a new one ... is that normal or I have a problem ?

like image 475
Naughty.Coder Avatar asked Feb 03 '26 06:02

Naughty.Coder


2 Answers

The manual says:

Alternatively, you can use the constant SID which is defined if the session started. If the client did not send an appropriate session cookie, it has the form session_name=session_id. Otherwise, it expands to an empty string. Thus, you can embed it unconditionally into URLs.

It's not meant to contain the session id, it's meant to be attached to URLs if cookies are disabled.

like image 141
deceze Avatar answered Feb 04 '26 21:02

deceze


Yes, it is normal. this constant being populated only when no cookie present. Why do you think you have any problem? What's the use of this constant anyway?

like image 37
Your Common Sense Avatar answered Feb 04 '26 19:02

Your Common Sense