[PHP]Criminals game script

Skilled Illusionist
Joined
Jan 14, 2005
Messages
395
Reaction score
2
hello,
i got question : how i can let it display only figures and not letters
maybe a google link or something coz i dont know how to searsh it now i got this code

Code:
<?php
session_start();
$width      = 100; // breedte
$height     =  40; // hoogte
$len        =  6; // lengte tekst
$fontsize   =  15; // lettertype

unset($random_text);

$lchar = 0;
$char  = 0;
/**************************************************
$random_text is de code
**************************************************/
// tekst maken
for($i = 0; $i < $len; $i++) {
    while($char == $lchar) {
        $char = rand(48, 109);
        if($char > 57) $char += 7;
        if($char > 90) $char += 6;
    } 
    $random_text .= chr($char);
    $lchar = $char;
}

$fontwidth  = ImageFontWidth($fontsize) * strlen($random_text);
$fontheight = ImageFontHeight($fontsize);

// afbeelding grootte
$im = @imagecreate($width,$height);

// achtergrond maken
$background_colour = imagecolorallocate($im, 204, 0, 0);

// tekst kleur
$text_colour = imagecolorallocate($im, rand(150,255), rand(150,255), rand(150,255)); 

// border
imagerectangle($im, 0, 0, $width-1, $height-1, $text_colour);

// string tekenen
imagestring($im, $fontsize, rand(6, $width-$fontwidth-3), rand(2, $height-$fontheight-3), $random_text, $text_colour);

//output
header("Content-type: image/png");
imagepng($im,'',80);

imagedestroy($im);

$_SESSION["verify"] = $random_text;
?>

ty - passie
 
Figures? What do you mean?
 
As most of you figured by now I don't speak PHP but assuming you want a random text string with only special characters and numbers here is some VB.NET code.

Code:
    'Define [default key] values
    Dim s_PublicKey = "1234567890!@#$%^&*()-=[]{};:,.<>/?\_ +"

    Public Function CreateRandomPassword(ByVal s_Length As Integer) As String
        'be sure things are randomized
        Randomize()

        'declare temporary variables to do a loop and store the password
        Dim s_Password As String = ""
        Dim x As Integer

        'loop as long as the password is to be required
        For x = 1 To s_Length Step 1
            s_Password &= Mid(s_PublicKey, CInt(Rnd() * Len(s_PublicKey)) + 1, 1)
        Next

        'return password to function
        Return s_Password
    End Function

It is a partial code for a self-developed encoding mechanism thus the code might not optimized for your situation (for example having the [s_PublicKey] defined outside the function is probably not required in your situation)
 
PHP:
<?php
function randomkeys($length)
{
    $pattern = "~!@#$%^&*()_+=-,./<>?'\"[]\{\}";
    $key  = $pattern{rand(0,35)};
     $count = strlen($pattern);
     for($i=1;$i<$length;$i++)
    {
        $key .= $pattern{rand(0,$count)};
    }
    return $key;
}
?>
Kudos to php.net my best friend ^_^
That should do, a slight mod from a function posted on php.net
Not sure if {} need to be \'ed or not =?
 
Code:
function randomkeys($length) {
    $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
    for ($x = 1; $x <= $length; $x++)
    {
        $number = rand(1, strlen($chars));
        $key .= substr($chars, $number - 1, 1);
    }

    return $key;
}
 
Back