win82 Posted April 22, 2008 Share Posted April 22, 2008 Hello I have a simple code to display the session constant and the values of Session variable. But the SID is not displayed. Can someone say the reason for this ? The code is below: <?php session_start(); session_register('your_id','100'); echo "<BR> Session Constant is: ".SID; echo "<BR>--------------------------------------------------- <BR>"; print_r($_SESSION); ?> Regards, PHP Developer, India. Link to comment https://forums.phpfreaks.com/topic/102324-php-session-constant-sid/ Share on other sites More sharing options...
DarkWater Posted April 22, 2008 Share Posted April 22, 2008 Not sure why...You can just use session_id(), because it returns the current SID. So: echo "<br />Session ID is: " . session_id(); Link to comment https://forums.phpfreaks.com/topic/102324-php-session-constant-sid/#findComment-523917 Share on other sites More sharing options...
jonsjava Posted April 22, 2008 Share Posted April 22, 2008 Do you have register_globals set to on? if so, it won't work <?php session_start(); ini_set('register_globals', 0); session_register('your_id','100'); echo "<BR> Session Constant is: ".SSID; echo "<BR>--------------------------------------------------- <BR>"; print_r($_SESSION); ?> Link to comment https://forums.phpfreaks.com/topic/102324-php-session-constant-sid/#findComment-523920 Share on other sites More sharing options...
win82 Posted April 22, 2008 Author Share Posted April 22, 2008 Do you have register_globals set to on? if so, it won't work No. I have checked on the php.ini and register_globals is turned off. Link to comment https://forums.phpfreaks.com/topic/102324-php-session-constant-sid/#findComment-523934 Share on other sites More sharing options...
DarkWater Posted April 22, 2008 Share Posted April 22, 2008 Did you try my suggestion? Link to comment https://forums.phpfreaks.com/topic/102324-php-session-constant-sid/#findComment-523936 Share on other sites More sharing options...
jonsjava Posted April 22, 2008 Share Posted April 22, 2008 Ok, then the next thing is a question: are you meaning do decare 2 separate session variables without setting them? when you do this: <?php session_start(); session_register('your_id','100'); that's what you are doing. You still need to set each with a <?php $_SESSION['your_id'] = "bleh"; ?> I didn't mention that before because your print_r would/should have outputted an array with no set values. Link to comment https://forums.phpfreaks.com/topic/102324-php-session-constant-sid/#findComment-523937 Share on other sites More sharing options...
jonsjava Posted April 22, 2008 Share Posted April 22, 2008 oh, and I agree with Dark. I just didn't mention it earlier because I "nuked" the crap out of the question, ignoring the question entirely. sorry about that. I get ahead of myself sometimes. Link to comment https://forums.phpfreaks.com/topic/102324-php-session-constant-sid/#findComment-523939 Share on other sites More sharing options...
win82 Posted April 22, 2008 Author Share Posted April 22, 2008 Did you try my suggestion? Yes friend.. It works fine. echo "<BR>Session ID & Value: ".session_name().'='.session_id(); Link to comment https://forums.phpfreaks.com/topic/102324-php-session-constant-sid/#findComment-523945 Share on other sites More sharing options...
win82 Posted April 22, 2008 Author Share Posted April 22, 2008 I didn't mention that before because your print_r would/should have outputted an array with no set values. No..You are wrong in that. That case also, the print_r display an array with the registered name & value. Link to comment https://forums.phpfreaks.com/topic/102324-php-session-constant-sid/#findComment-523949 Share on other sites More sharing options...
DarkWater Posted April 22, 2008 Share Posted April 22, 2008 Did you try my suggestion? Yes friend.. It works fine. echo "<BR>Session ID & Value: ".session_name().'='.session_id(); No problem. =D I wonder why the constant wouldn't work. Link to comment https://forums.phpfreaks.com/topic/102324-php-session-constant-sid/#findComment-523951 Share on other sites More sharing options...
win82 Posted April 22, 2008 Author Share Posted April 22, 2008 No problem. =D I wonder why the constant wouldn't work. Me to... And the truth is that, SID outputs value at the first time when I loaded the page.. After that no values.. Link to comment https://forums.phpfreaks.com/topic/102324-php-session-constant-sid/#findComment-523963 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.