Page 1 of 1

SESSION

Posted: Mon Feb 03, 2003 6:21 pm
by jamal
Hi Guys,
I need your help please.
Can you point to me the error in this code??
The counting supposed to increment by 1 everytime
I reload the page but it is not just working.
Thanks
God Bless You

Code: Select all

<?
session_start();
session_register("SESSION");

if (!isset($SESSION)) {
        $SESSION["count"] = 0;
        echo "<li>Counter initialized, please reload this page to see it increment";
} else {
        echo "<li>Waking up session $PHPSESSID";
        $SESSION["count"]++;
}
echo "<li>The counter is now $SESSION[count] ";
?>

Posted: Tue Feb 04, 2003 1:25 am
by redcircle
$SESSION should be $_SESSION. and when using superglobals you do not need to use the annoying session_register. so your code should look like this.

Code: Select all

<? 
session_start(); 

if (!isset($_SESSION&#1111;'count'])) &#123; 
        $_SESSION&#1111;"count"] = 0; 
        echo "<li>Counter initialized, please reload this page to see it increment"; 
&#125; else &#123; 
        echo "<li>Waking up session ".$_COOKIE&#1111;'PHPSESSID']; 
        $_SESSION&#1111;"count"]++; 
&#125; 
echo "<li>The counter is now ".$_SESSION&#1111;'count']; 
?>