Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jan 2007
    Posts
    217
    Thanks
    9
    Thanked 0 Times in 0 Posts

    wierd session error

    PHP Code:
    $token rand(1,1000000000000);
    $_SESSION['token'] = $token;

    <
    a href=?action=get&&token=$token 
    When i try to compare these two values, it says they are in correct. So i echo'd them both out, and for some wierd reason the value in the session is always a - number, but the one in the variable is a positive number.

    Whats' wrong :X?

  • #2
    New Coder
    Join Date
    Jul 2008
    Location
    New York
    Posts
    24
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Arrow

    When I run your code I get a negative number for $token, so I removed one of the zeros from rand() and started to return positive numbers. Don't know if that helps or not...

    Trevor

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    The number 1000000000000 is too large to store in a signed integer, so it causes the number to wrap back to negative digits. The maximum number you can use is 2147483647, or getrandmax(). Windows only has enough space to handle a signed short, so its max is 32768 with getrandmax(). Use mt_rand to handle larger numbers.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

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