SESSION

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
jamal
Forum Commoner
Posts: 57
Joined: Sat Oct 26, 2002 7:53 pm
Location: London

SESSION

Post 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] ";
?>
User avatar
redcircle
Forum Commoner
Posts: 43
Joined: Fri Jan 31, 2003 8:47 pm
Location: michigan, usa

Post 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']; 
?>
Post Reply