vorrei creare delle scritte random da usare come codice di conferma, come nei forum
vorrei creare delle scritte random da usare come codice di conferma, come nei forum
hai provato a usare dei numeri che saranno poi usati come numeri della tabella ascii?
generi un numero a caso con la funzione rand(), poi usi quel numero con la funzione chr()
![]()
Codice PHP:
<?
//set maximum password length (this is the only configuration require)
$max_pass_len = 50;
$pass_len = 10;
$pass_len_check = is_numeric($pass_len);
if (!$pass_len_check) { $error = "true"; }
if (($pass_len > $max_pass_len) or ($pass_len < 1)) { $error = "true"; }
if ($error != "true")
{
//set alphabet arrays
$alpha_lower = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z");
$alpha_upper = array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z");
//set option arrays
$options = array("AU", "AL", "NU");
//seed the random generator
srand((double) microtime() * 1000000);
//create password
for ($loop = 0; $loop < $pass_len; $loop++)
{
$pass_numeric = rand(0, 9);
$pass_alpha_array_select = rand (0, 25);
$item = array_rand($options, 1);
if ($loop == 0)
{
if ($options[$item] == "NU") { $password = $pass_numeric; }
if ($options[$item] == "AL") { $password = $alpha_lower[$pass_alpha_array_select]; }
if ($options[$item] == "AU") { $password = $alpha_upper[$pass_alpha_array_select]; }
}
else
{
if ($options[$item] == "NU") { $password .= $pass_numeric; }
if ($options[$item] == "AL") { $password .= $alpha_lower[$pass_alpha_array_select]; }
if ($options[$item] == "AU") { $password .= $alpha_upper[$pass_alpha_array_select]; }
}
}
}
echo $password;
?>
questo anche non è male
una domanda: ma come potrei fare a creare un'immagine dinamica che cambia il contenuto, cioè la scritta?, e in più come ha suggerito stefano, come posso fare poi a validare se la password è vera o falsa?
ciao io sono niubbo sul php ma su un sito un un MMRPOG <me pare si scrivi così> ho visto che ci sono le firme dinamiche ti posto il codice php anche se non ho capito bene come funziona..oddio un po si ma devo studiarlo bene ^^
<?php
error_reporting(0);
include_once('./00config.php');
header("Content-type: image/png");
$name = $_GET['name'];
if ($name == null || $name == '' || !preg_match('/^[a-z0-9]*$/i', $name) || (strlen($name) > 12)) {
$name = "";
}
$users = file_get_contents("{$backend}getOnlineCount.php");
if ($users === false) {
$users = "N/A";
} else {
$users = $users . " users online";
}
$level = "";
$exp = "";
if ($name != "") {
$contents = file_get_contents("{$backend}getLevelSexJobExp.php ?verify={$magickey}&name={$name}");
if (contents !== false) {
$lines = preg_split('/\n/', $contents, -1, PREG_SPLIT_NO_EMPTY);
$level = $lines[0];
$exp = $lines[3];
if ($level != "Failed") $name .= " Level " . $level;
if ($exp != "Failed") $name .= " " . $exp . "%";
}
}
$im = imagecreatefrompng("images/KaoriBanner".rand(1, 7).".png");
$cBlack = imagecolorallocate($im, 0, 0, 0);
$cYellow = imagecolorallocate($im, 255, 255, 0);
$cViolet = imagecolorallocate($im, 255, 0, 255);
if ($name != "") {
imagestring($im, 5, 10, 60, $name, $cBlack);
}
imagestring($im, 5, 10, 75, $serverName, $cYellow);
imagestring($im, 5, 10, 90, $users, $cViolet);
imagepng($im);
imagedestroy($im);
?>
Immagine 1
Immagine 2 dello script
Spero di non creare problemi o infrangere regole se posto le immagini..tanto Kaori non si arrabbia visto che ha dato lo script :P
Tu guarda...