[PHP] newbie having problem with SID
Hi, I'm just a few weeks into learning PHP, and now wants to understand sessions. But I've run into trouble with the very first script I've tried, even though it's more or less copied from the PHP manual. ?php include (html_functions.php); $title = Anders testing SID; $header = ; html_begin ($title, $header); if (!session_is_registered('count')) { session_register('count'); $count = 1; } else { $count++; } ? ?php echo $_COOKIE[PHPSESSID]? BR BR Hello visitor, you have seen this page ?php echo $count; ? times.p To continue, A HREF=visasida.php??php echo SID?click here/A ?php html_end(); ? The session id isn't attached to the link in the end of the script, and therefore $count always is '1', even after I click the link. But the $_COOKIE[PHPSESSID] does contain a value. I'm using PHP 4.2.2 and according to phpinfo() session.use_trans_sid is set to '1'. What I'm missing? Best regards, Anders Thoresson -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] newbie having problem with SID
At 12:46 04.12.2002, Anders Thoresson spoke out and said: [snip] ?php echo $_COOKIE[PHPSESSID]? BR BR Hello visitor, you have seen this page ?php echo $count; ? times.p To continue, A HREF=visasida.php??php echo SID?click here/A The session id isn't attached to the link in the end of the script, and therefore $count always is '1', even after I click the link. But the $_COOKIE[PHPSESSID] does contain a value. [snip] Your system date is way off (Dec 4th instead of Dec 16th), so I may be late in noticing your post... The SID constant is only set if necessary, which means if you don't (or can't) use a session cookie. If your server is setup to use session cookies, and the client browser returns it, SID will be empty. In this situation even the trans_sid mechanism would change nothing in HTML output. Anyway your problem is most certainly not tied to that, as the session should perfectly being set up using the session cookie. You're using session_register in version 4.2.2, where globals are not registered by default (check the register_global setting in php.ini). You should use the session array ($_SESSION['count']) to handle session persistent data: html_begin ($title, $header); if (!array_key_exists('count', $_SESSION)) { $_SESSION['count'] = 1; } else { $_SESSION['count']++; } end then ?php echo $_COOKIE[PHPSESSID]? BR BR Hello visitor, you have seen this page ?php echo $_SESSION['count']; ? times.p To continue, A HREF=visasida.phpclick here/A -- O Ernest E. Vogelsinger (\) ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] newbie having problem with SID
You should use the session array ($_SESSION['count']) to handle session persistent data: Thanks. That solved my problem. At least for the moment. I know realize that all books and all web site-prints I have covering sessions are not using the session array, but the older way to handle sessions with session_register(),session_is_registered() and session_unregister(). There are obviously differences in how things are handled now and how they were handled then. Can someone point me to a good session tutorial based on the session array rather than the pre-PHP 4.2 (I think that's the version when this was changed)? Best regards, Anders Thoresson -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] newbie having problem with SID
--- Anders Thoresson [EMAIL PROTECTED] wrote: There are obviously differences in how things are handled now and how they were handled then. Yes, but I don't think there are as many differences as you think. Can someone point me to a good session tutorial based on the session array rather than the pre-PHP 4.2 (I think that's the version when this was changed)? I would recommend the online manual for date-sensitive information: http://www.php.net/manual/en/ref.session.php Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php