Page 1 of 1
Random numbers
Posted: Thu Dec 04, 2008 11:33 am
by pauls74462
Code: Select all
<?php
// Make Random Number
$R=(rand(1,9));
echo $R;
?>
I have the above code, this $R is needed on other pages. How do I make it carry over to the other pages. On the second page then (echo $R;) does not show up.
I have searched for thks and can't seem to find an answer. I can't use the command to pit in in a text file and store on the server, as other users will over write it.
Any suggestions?
Paul
Re: Random numbers
Posted: Thu Dec 04, 2008 12:06 pm
by Mark Baker
pauls74462 wrote:I have the above code, this $R is needed on other pages. How do I make it carry over to the other pages. On the second page then (echo $R;) does not show up.
I have searched for thks and can't seem to find an answer. I can't use the command to pit in in a text file and store on the server, as other users will over write it.
You either pass it in the URL for the next page, and access it as a $_GET parameter, or you store it in a session file (which won't get overwritten by other users)
Re: Random numbers
Posted: Thu Dec 04, 2008 12:16 pm
by Reviresco
Save it in a $_SESSION[] variable (
http://www.php.net/session ) or you could put it in a $_GET[] variable for each new page such as:
http://www.example.com/page2.php?R=127
In the above examples, you would have either:
$_SESSION['R']
or
$_GET['R']
Re: Random numbers
Posted: Thu Dec 04, 2008 4:25 pm
by guygk
Read about PHP sessions (
http://php.net/sessions), they are used to keep data alive for user only while session is alive. If you want to store data for longer time period you can use cookies or * database instead.