Results 1 to 3 of 3

Thread: How to fix randomized number when page refresh?

  1. #1
    Join Date
    Aug 2007
    Location
    Malaysia
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to fix randomized number when page refresh?

    Hi..guys! I am using mt_rand() to generate a random number,however how can prevent it keep on changing when page refresh?Thanks...

    PHP Code:
    $random mt_rand(100000999999); 

  2. #2
    Join Date
    Aug 2007
    Location
    Malaysia
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Well, I put it into session,problem resolved

    PHP Code:
    <? 
    session_start
    ();
    if(!isset(
    $_SESSION['random'])){ 
         
    $_SESSION['random'] = mt_rand(100000999999); 

    $random $_SESSION['random']; 
    ?>
    PHP Code:
    <?php echo $random?>

  3. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Or there might be a better way to design the system so you don't need to deal with sessions. Seems extreme to me, but depends on the case.
    Sessions are the only way to keep it from being regenerated, but if you give a bit more info, there might be a workaround in a broader sense.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •