Is there a way to set a value according to the number of tim

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
lovelf
Forum Contributor
Posts: 153
Joined: Wed Nov 05, 2008 12:06 am

Is there a way to set a value according to the number of tim

Post by lovelf »

Is there a way to set a value for a variable according to the number of times the file has been loaded ?

Example:

for first time loaded $value = hello.
for second time loaded $value = bye.

echo "$value";
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Is there a way to set a value according to the number of tim

Post by Benjamin »

Yes there is. You will need to track a persistent variable such as a $_SESSION, $_COOKIE, $_POST or $_GET.
mubeena
Forum Newbie
Posts: 17
Joined: Fri Jan 30, 2009 4:26 am

Re: Is there a way to set a value according to the number of tim

Post by mubeena »

Try this code,

Code: Select all

<?php
   session_start();
// Use $HTTP_SESSION_VARS with PHP 4.0.6 or less
if (!isset($_SESSION['count'])) {
    $_SESSION['count'] = 0;
} else {
    $_SESSION['count']++;
}
print $_SESSION['count'];
?> 
 
lovelf
Forum Contributor
Posts: 153
Joined: Wed Nov 05, 2008 12:06 am

Re: Is there a way to set a value according to the number of tim

Post by lovelf »

Thank you all.
Post Reply