Sid Generator

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Sid Generator

    i know im probably missing something here, but for some reason, if i use the following code directly into a file, it works perfectly..
    however, trouble arises if i try to set it as a function within an included .php file or even

    I'm not exactly sure how else to describe it or what other information is needed but its really getting on my nerves now lol .. im guessing it might be something within the function that only allows it to be executed within the main file?
    if so, is there any chance that an alternative could be suggested?

    code placed directly into home.php and/or directly into the include file (not at the same time)
    Code:
    if($sid==""){
    srand ((double) microtime( )*1000000);
    $random_number = rand( );
    $sid = md5($random_number);
    }

    code as a function
    Code:
    function checksid($sid){
    if($sid==""){
    srand ((double) microtime( )*1000000);
    $random_number = rand( );
    $sid = md5($random_number);
    }
    }

    #2
    Code:
    function checksid($sid){
    if(empty($sid)){
    $sid = preg_replace('/\W/', '', md5(rand()));
    }
    return $sid;
    }
    Advertise your mobile site for FREE with AdTwirl

    Comment


      #3
      Code:
      echo "sid1 = $sid 
       \n";  
      
      if($sid==""){
      srand ((double) microtime( )*1000000);
      $random_number = rand( );
      $sid = md5($random_number);
      }
      
      echo "sid2 = $sid 
       \n";
      Code:
      echo "sid1 = $sid 
       \n";  
      
      if(empty($sid)){
      $sid = preg_replace('/\W/', '', md5(rand()));
      }
      
      echo "sid2 = $sid 
       \n";
      both of the above snippets work perfectly directly inside each file with the first sid being blank, the second having a random value .. but then when i put either of those into a function (as shown below), it ceases to output an sid

      Code:
      echo "sid1 = $sid 
       \n";  
      
      checksid($sid);
      
      echo "sid2 = $sid 
       \n";
      FUNCTION
      Code:
      function checksid($sid){
      if(empty($sid)){
      $sid = preg_replace('/\W/', '', md5(rand()));
      }
      return $sid;
      }
      Code:
      function checksid($sid){
      if($sid==""){
      srand ((double) microtime( )*1000000);
      $random_number = rand( );
      $sid = md5($random_number);
      }
      }

      Comment

      Working...
      X