Gå til innhold

Anbefalte innlegg

Videoannonse
Annonse

<?php

function randomCode($length)
{
  $random = md5(time());
  $code = substr($random, 0, $length); 

return $code;
}

?>

 

Du bruker funksjonen slik: randomCode(8) - Vil da generere en hash på 8 tegn

 


<?php

if($_POST['code'] != $code)
{
 echo "oi oi, du må nok skrive inn koden riktig du..";
 exit;
}

else
{
  header("Location: forum.php");
}

?>

Sikkert litt dårlig forklart, men bare spør hvis du ikke forstod hvordan det brukes..

Lenke til kommentar

Ingen av de to scriptene over vil fungere slik de står nå, det må noe mere kode til, bl.a Sessions bør/må brukes. Det finnes mange ferdige captcha scripts ute på nettet, her er ett simpelt ett som jeg fant

 

image.php

<?php
header("Content-type: image/gif");
session_start();
$CAPTCHA = @imagecreate(100, 50)or die("There was a problem creating the Image string");
$bgcolor = imagecolorallocate($CAPTCHA, 255, 255, 255);
$textcolor = imagecolorallocate($CAPTCHA, 0, 0, 0);
imagestring($CAPTCHA, 4, 5, 5,  $_SESSION['image_string'], $textcolor);
imagegif($CAPTCHA);
imagedestroy($CAPTCHA);
?>

 

verify.php

<?php
session_start();

// Print HTML for page.

print("<html>");
print("<head>");
print("<title>CAPTCHA</title>");
print("</head>");
print("<body>");

// See if the form has been filled in.

if(!isset($_POST['verify']))
{
// Generate a String of numbers.
$ImageString = rand("0", "9").rand("0", "9").rand("0", "9").rand("0", "9").rand("0", "9");
$_SESSION['image_string'] = $ImageString;

// Put the string into an image and display an image.

print("<img src=\"image.php\" alt=\"\" /> <br />");

print("<form name=\"verify\" method=\"post\" action=\" " . $_SERVER['REQUEST_URI'] . " \">");
print("<input type=\"text\" name=\"string\" size=\"15\" id=\"formfield\">");
print("<input type=\"submit\" name=\"verify\" value=\"Verify\" id=\"submitbutton\">");
print("</form>");

} else {

// Check the inputted string.

if($_POST['string'] !== $_SESSION['image_string'])
{
$CorrectString = '0';
echo 'Incorrect Image string entered.';
} else {
echo 'Correct Image string entered.';
$CorrectString = '1';
}

session_destroy();  // Destroy the Image string.

}

print("</body>");
print("</html>");

?>

 

readme.txt

CAPTCHA script by pdstudios.net

 

Simply upload the files to your webserver and you are done.

 

There is a variable called $ConnrectString which will be the value of 1 if the string is correct. Use this to link with other scripts.

 

http://www.pdstudios.net for support

 

Håper dette er til litt nytte

Lenke til kommentar

Opprett en konto eller logg inn for å kommentere

Du må være et medlem for å kunne skrive en kommentar

Opprett konto

Det er enkelt å melde seg inn for å starte en ny konto!

Start en konto

Logg inn

Har du allerede en konto? Logg inn her.

Logg inn nå
×
×
  • Opprett ny...