Page 1 of 1
Is there a way to set a value according to the number of tim
Posted: Sat Jan 31, 2009 1:02 am
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";
Re: Is there a way to set a value according to the number of tim
Posted: Sat Jan 31, 2009 1:05 am
by Benjamin
Yes there is. You will need to track a persistent variable such as a $_SESSION, $_COOKIE, $_POST or $_GET.
Re: Is there a way to set a value according to the number of tim
Posted: Sat Jan 31, 2009 1:22 am
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'];
?>
Re: Is there a way to set a value according to the number of tim
Posted: Sat Jan 31, 2009 2:41 am
by lovelf
Thank you all.