Jump to content

[SOLVED] Random Function


Canman2005

Recommended Posts

Hi

 

I have a function that creates a random string, the function looks like

 

<?php
  function randomkeys($length)
  {
   $pattern = "1234567890abcdefghijklmnopqrstuvwxyz";
   for($i=0;$i<$length;$i++)
   {
     $key .= $pattern{rand(0,35)};
   }
   return $key;
  }
?>

 

The function has worked fine until the server guys did some changes to the server, now when you include the function, you get the error

 

Notice: Undefined variable: key in C:\www\mysite\functions\rand.php on line 7

 

Does anyone know why this is happening?

 

Thanks

 

Ed

Link to comment
https://forums.phpfreaks.com/topic/48162-solved-random-function/
Share on other sites

they probably upp'd the error level to NOTICE, this error has always been there, just not shown..

 

do

 

<?php
  function randomkeys($length)
  {
   $key = '';
   $pattern = "1234567890abcdefghijklmnopqrstuvwxyz";
   for($i=0;$i<$length;$i++)
   {
     $key .= $pattern{rand(0,35)};
   }
   return $key;
  }
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.