Initialise a variable once?

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
phpnitemare
Forum Newbie
Posts: 12
Joined: Sat Mar 28, 2009 1:14 pm

Initialise a variable once?

Post by phpnitemare »

hello,

I am trying to set a variable to 0 when the webpage first loads. Doing this in my index.php currently means the variable would contantly get reset changing the pointer variable back to 0. Even using the if statement below causes the same problem as without establishing pointzero to 0 the variable will not be initialised however the if statement will always be true. How can I build it so that pointer is only set to 0 once upon first website load?


$_SESSION["pointzero"] = 0;
if($_SESSION["pointzero"] == 0) {
$pointer = 0;
$_SESSION["pointer"] = $pointer;
$_SESSION["pointzero"] = 1;
}
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Initialise a variable once?

Post by requinix »

What was wrong with your other thread?

One thread per question. Not two. Not three.
Post Reply