Sid Generator

Started on the old forum in April 2007 · view the original in the archive · old links redirect here

2 replies · 1,889 views · started 19 years ago · 1 min read

Guest #1

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)

if($sid==""){
srand ((double) microtime( )*1000000);
$random_number = rand( );
$sid = md5($random_number);
}

code as a function

function checksid($sid){
if($sid==""){
srand ((double) microtime( )*1000000);
$random_number = rand( );
$sid = md5($random_number);
}
}
Guest #3
echo "sid1 = $sid 
 \n";  

if($sid==""){
srand ((double) microtime( )*1000000);
$random_number = rand( );
$sid = md5($random_number);
}

echo "sid2 = $sid 
 \n";
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

echo "sid1 = $sid 
 \n";  

checksid($sid);

echo "sid2 = $sid 
 \n";

FUNCTION

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

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close