LastMitch
Industrious Poster
4,118 posts since Mar 2012
Reputation Points: 132
Solved Threads: 334
Skill Endorsements: 45
To add a new fibonacci number on each refresh you should store each previous and current value in a session.
session_start();
// on the beginning you have 0 and 1
if(!isset($_SESSION['previous']) || !isset($_SESSION['current'])) {
$_SESSION['previous'] = 0;
$_SESSION['current'] = 1;
echo $_SESSION['previous'];
echo ' ';
echo $_SESSION['current'];
} else {
$current = $_SESSION['previous'] + $_SESSION['current'];
echo $current;
$_SESSION['previous'] = $_SESSION['current'];
$_SESSION['current'] = $current;
}
broj1
Nearly a Posting Virtuoso
1,211 posts since Jan 2011
Reputation Points: 167
Solved Threads: 164
Skill Endorsements: 13
I doubt the OP is still awaiting an answer, but for anybody else -
Agreed - sessions would be the way to go IMO.
diafol
Keep Smiling
10,625 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,506
Skill Endorsements: 57
I have just noticed that the question is mentioning cookies. Well the principle is the same as using session.
Anyway, it was just nice to do a little brain exercise.
broj1
Nearly a Posting Virtuoso
1,211 posts since Jan 2011
Reputation Points: 167
Solved Threads: 164
Skill Endorsements: 13