Random Code Script
Random Code Script
Community / Bookmark
69 Comments(s)
↴ ↴
Random code script
about: ({ changelog recent_tips
version
@tims15 version tipper @phpnovice
social notes: 0
tipped
Jun 06.2005 Jun 06.2005 — #
}); },{ amount
version },{
You could set a cookie that would
legal: ({ notes: tipper
I need a script that would show a
terms: },{ tipped perform either function, but the visitor
privacy
random version
code when the page is loaded amount could clear their cookies and you
analytics notes: },{ would be back to square-one. The
(codes
}); would be preset
},{ by me). Each tipper
code can only be shownversion
to a user once tipped only other solution is to use server-
(v important). When thenotes:
page is amount side code and a database.
})... })...
refreshed, or visited at a later date by
reply?
the same person who has already
requested a code, I would need the code
to either be the same, or have a
message saying they have already
requested a code (this isn’t as
important). @tims15 author
0
Jun 07.2005 — #
reply?
@phpnovice
0
Jun 07.2005 — #
function getCookie(name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
function getCookieVal(offset) {
var endstr = document.cookie.indexOf (";", offs
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offse
}
function setCookie(name, value) {
var argv = setCookie.arguments;
var argc = setCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expir
((path == null) ? "" : ("; path=" + path)) + <
((domain == null) ? "" : ("; domain=" + domain)
((secure == true) ? "; secure" : "");
}
function delCookie(name) {
exp = new Date();
exp.setTime(exp.getTime() - (24*60*60*1000));
var cval = getCookie(name);
cval = (cval == null) ? "" : cval;
document.cookie = name + "=" + cval + "; expire
}
reply?
@tims15 author
0
Jun 08.2005 — #
reply?
@phpnovice
0
Jun 08.2005 — #
alert("<%=SetCode()%>");
reply?
@tims15 author
0
Jun 13.2005 — #
reply?
@phpnovice
0
Jun 13.2005 — #
reply?
@tims15 author
0
Jun 13.2005 — #
reply?
:
@phpnovice
0
Jun 13.2005 — #
This, in ASP:
alert("<%=SetCode()%>");
is this, in PHP:
alert("<?=SetCode()?>");
reply?
@tims15 author
0
Jun 13.2005 — #
reply?
@phpnovice
0
Jun 13.2005 — #
reply?
@tims15 author
0
Jun 14.2005 — #
reply?
:
@phpnovice
0
Jun 14.2005 — #
reply?
@tims15 author
0
Jun 14.2005 — #
reply?
@phpnovice
0
Jun 14.2005 — #
reply?
:
@tims15 author
0
Jun 14.2005 — #
reply?
@phpnovice
0
Jun 14.2005 — #
<i>
</i>Response.Buffer = True
Response.Cookie("private_code") = private_code
Response.Cookie("private_code").Expires = DateA
Response.Cookie("private_code").Path = "/"
:
and the following will test for the
cookie when they return:
<i>
</i>If Len(Request.Cookie("private_code") >
Response.Write "<p>Your code is: " &
Else
Response.Write "<p>Your code is: " &
End If
reply?
@tims15 author
0
Jun 15.2005 — #
reply?
@phpnovice
0
Jun 15.2005 — #
reply?
@tims15 author
0
Jun 15.2005 — #
reply?
0
:
0
@phpnovice
Jun 15.2005 — #
reply?
@tims15 author
0
Jun 15.2005 — #
reply?
@phpnovice
0
Jun 15.2005 — #
reply?
@tims15 author
0
Jun 15.2005 — #
reply?
@phpnovice
0
Jun 15.2005 — #
reply?
:
@tims15 author
0
Jun 16.2005 — #
reply?
@phpnovice
0
Jun 16.2005 — #
reply?
@tims15 author
0
Jun 17.2005 — #
reply?
@phpnovice
0
Jun 17.2005 — #
reply?
@tims15 author
0
Jun 17.2005 — #
reply?
@phpnovice
0
Jun 17.2005 — #
reply?
@tims15 author
0
Jun 18.2005 — #
reply?
@phpnovice
0
Jun 18.2005 — #
reply?
@tims15 author
0
Jun 18.2005 — #
reply?
@phpnovice
0
Jun 18.2005 — #
reply?
:
@tims15 author
0
Jun 19.2005 — #
reply?
@phpnovice
0
Jun 19.2005 — #
[code=php]
<?php
$html = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTM
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Language" content="en
<meta http-equiv="Content-Type" content="text/h
<title>User Details</title>
</head>
<body>
';
//
$file = 'user_details.csv'; // master path & fi
$copy = 'user_details.old'; // temporary path &
//
$cookie = 'user_details'; // cookie name
$expire = time() + (365*24*60*60); // cookie ex
//
function fputcsv($fp, $array, $delimiter=',')
{
$line = '';
foreach($array as $val):
$val = str_replace("rn", "n", $val);
if(is_numeric($val)):
$line .= $val . $delimiter;
else:
$line .= '"' . str_replace('"', '""', $val) . '
endif;
endforeach;
$line = substr($line, 0, (strlen($delimiter) *
return fwrite($fp, $line);
}
//
if(isset($_COOKIE[$cookie])):
$html .= '<p>' . $_COOKIE[$cookie] . "</p>n";
else:
if(!file_exists($file)):
$html .= '<p>User details file not found.</p>'
else:
@unlink($copy);
// search user file for available details
:
$fp = fopen($file, "r");
while($user = fgetcsv($fp, 35)):
if(!isset($user[2])
|| $user[2] == 0):
break;
endif;
endwhile;
fclose($fp);
//
endif;
//
if(!isset($user[0])
|| !isset($user[1])
|| (isset($user[2]) && $user[2] != 0)):
$html .= '<p>Sorry, no user details available.<
else:
if(!rename($file, $copy)):
$html .= '<p>Unable to rename user details file
else:
$delcopy = true;
// update file to flag user details as taken
$fc = fopen($copy, "r");
$fp = fopen($file, "w");
while($data = fgetcsv($fc, 32)):
if($data[0] == $user[0]
&& $data[1] == $user[1]):
$data[2] = 1;
endif;
if(!fputcsv($fp, $data)):
$html .= '<p>User details update failed.</p>' .
$delcopy = false;
break;
endif;
endwhile;
fclose($fp);
fclose($fc);
//
if($delcopy):
$str = "User name: {$user[0]}, password: {$user
setcookie($cookie, $str, $expire, '/');
$html .= '<p>' . $str . "</p>n";
unlink($copy);
endif;
endif;
endif;
endif;
//
$html .= '
</body>
</html>
';
echo $html;
?>
[/code]
reply?
:
@tims15 author
0
Jun 19.2005 — #
reply?
@phpnovice
0
Jun 19.2005 — #
username1,password1
username2,password2
username3,password3
etc.
reply?
@tims15 author
0
Jun 19.2005 — #
reply?
@phpnovice
0
Jun 19.2005 — #
reply?
@tims15 author
0
Jun 20.2005 — #
reply?
@phpnovice
0
Jun 20.2005 — #
$cle =
'/subdirectory/user_details.csv';
reply?
@tims15 author
0
Jun 20.2005 — #
Line 15 is
reply?
@phpnovice
0
Jun 20.2005 — #
reply?
@tims15 author
0
Jun 20.2005 — #
reply?
@phpnovice
0
Jun 20.2005 — #
reply?
@tims15 author
0
Jun 21.2005 — #
reply?
@phpnovice
0
Jun 21.2005 — #
reply?
@tims15 author
0
Jun 22.2005 — #
lol ?
reply?
@tims15 author
0
Jul 03.2005 — #
reply?
0
:
0
@phpnovice
Jul 03.2005 — #
username1,password1
username2,password2
username3,password3
etc.
usercode1
usercode2
usercode3
etc.
reply?
@tims15 author
0
Jul 03.2005 — #
reply?
@phpnovice
0
Jul 03.2005 — #
reply?
:
@tims15 author
0
Jul 04.2005 — #
reply?
@phpnovice
0
Jul 04.2005 — #
reply?
@tims15 author
0
Jul 04.2005 — #
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-
Language" content="en-us">
<meta http-equiv="Content-Type"
content="text/html; charset=iso-
8859-1">
<title>User Details</title>
</head>
<body>
';
//
$copy = 'user_details.old'; //
temporary path & cle name
//
//
:
function fputcsv($fp, $array,
$delimiter=',')
$line = '';
foreach($array as $val):
if(is_numeric($val)):
else:
endif;
endforeach;
$line = substr($line, 0,
(strlen($delimiter) * -1)) . "n";
//
if(isset($_COOKIE[$cookie])):
else:
if(!cle_exists($cle)):
else:
:
@unlink($copy);
if(!isset($user[1])
|| $user[2] == 0):
break;
endif;
endwhile;
fclose($fp);
//
endif;
//
if(!isset($user[0])
else:
if(!rename($cle, $copy)):
else:
$delcopy = true;
:
// update cle to zag user details
as taken
if($data[0] == $user[0]
$data[1] = 1;
endif;
if(!fputcsv($fp, $data)):
$delcopy = false;
break;
endif;
endwhile;
fclose($fp);
fclose($fc);
//
if($delcopy):
unlink($copy);
:
endif;
endif;
endif;
endif;
//
$html .= '
</body>
</html>
';
echo $html;
?>
[/QUOTE]
reply?
@phpnovice
0
Jul 04.2005 — #
[code=php]if($data[0] == $user[0]
$data[1] = 1;
endif;[/code]
should be this:
[code=php]if($data[0] == $user[0]):
$data[1] = 1;
endif;[/code]
:
Otherwise, you'll also want to change
this line:
to this:
reply?
@tims15 author
0
Jul 05.2005 — #
<?php
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-
Language" content="en-us">
<meta http-equiv="Content-Type"
content="text/html; charset=iso-
8859-1">
<title>User Details</title>
:
</head>
<body>
';
//
$copy = 'user_details.old'; //
temporary path & cle name
//
//
$line = '';
foreach($array as $val):
if(is_numeric($val)):
else:
endif;
:
endforeach;
$line = substr($line, 0,
(strlen($delimiter) * -1)) . "n";
//
if(isset($_COOKIE[$cookie])):
else:
if(!cle_exists($cle)):
else:
@unlink($copy);
if(!isset($user[1])
|| $user[2] == 0):
break;
endif;
endwhile;
fclose($fp);
:
//
endif;
//
if(!isset($user[0])
else:
if(!rename($cle, $copy)):
else:
$delcopy = true;
if($data[0] == $user[0]):
$data[1] = 1;
endif;
if(!fputcsv($fp, $data)):
$delcopy = false;
:
break;
endif;
endwhile;
fclose($fp);
fclose($fc);
//
if($delcopy):
unlink($copy);
endif;
endif;
endif;
endif;
//
$html .= '
</body>
</html>
';
echo $html;
?>
[/QUOTE]
:
reply?
@phpnovice
0
Jul 05.2005 — #
reply?
@tims15 author
0
Jul 06.2005 — #
line 67 is
$data[1] = 1;
[/QUOTE]
reply?
@phpnovice
0
Jul 06.2005 — #
[code=php]
if($data[0] == $user[0]):
$data[1] = 1;
endif;
[/code]
reply?
@tims15 author
0
Jul 06.2005 — #
reply?
@phpnovice
0
Jul 06.2005 — #
reply?
@tims15 author
0
Jul 09.2005 — #
@phpnovice
0
Jul 09.2005 — #
reply?
@tims15 author
0
Jul 10.2005 — #
reply?
@phpnovice
0
Jul 10.2005 — #
Cheers.
reply?
@tims15 author
0
Jul 10.2005 — #
reply?
:
Also in #JavaScript
Indexing Question ?
Prompt