Jump to content

Does any one see anything wrong with this random id?


xlxprophetxlx

Recommended Posts

I can't seem to echo this out of a function:

 

mt_srand ((double) microtime() * 1000000);
$useridstring = md5(uniqid(mt_rand()));
$userfinal = "";

function useridfun(){
if($userfinal == ""){
	echo $useridstring;	
}elseif($userfinal == $userid){
	echo $userfinal;
}
}
useridfun()

 

This is pretty much driving me nuts.  I had it working earlier but now it doesn't seem to want to work.  If I print or echo $useridstring by itself it works but not within the function.  It got to be something I'm just over seeing.

 

Thanks!

Where's userid defined?

 

userid is defined further up in my coding but in this example it shouldn't matter since $userfinal == "" is true as shown.  and it's not outputting

 

echo $useridstring; for some reason.

You have a variable scope problem. The variable $userid inside the function has no relation to any similarly named function outside the function. You need to pass the value into the function if you want to use it. Same with the variable $userfinal.

 

Try something like this:

<?php
$userfinal = "";

function useridfun($userfinal, $userid)
{
        mt_srand ((double) microtime() * 1000000);
        $useridstring = md5(uniqid(mt_rand()));
if($userfinal == ""){
	$tmp = $useridstring;	
}elseif($userfinal == $userid){
	$tmp = $userfinal;
}
  return($tmp);
}
$userfinal = useridfun($userfinal, $userid);
echo $userfinal;
?>

 

Ken

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.