Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Test page one: Create image + Session
- session_start();
- function randomString() {
- $string = "abcdefghijklmnopqrstuvxyz1234567890";
- $final = "";
- for($i=0;$i<=7;$i++) {
- $number = rand(1, 35);
- $getString = substr($string, $number, 1);
- $final .= $getString;
- }
- return $final;
- }
- $_SESSION['CaptchaImage'] = randomString();
- $CaptchaImage = $_SESSION['CaptchaImage'];
- function createImage($randomString) {
- header ('Content-Type: image/png');
- $getImage = imagecreatetruecolor(80,20);
- $colorBackground = imagecolorallocate($getImage, 0, 0, 0);
- $colorString = imagecolorallocate($getImage, 125, 125, 125);
- $fontImage = imagestring($getImage, 2, 5, 5, $randomString, $colorString);
- $showImage = imagepng($getImage);
- $showImage = imagedestroy($getImage);
- return $showImage;
- }
- createImage($CaptchaImage);
- // Test page two: Show and test image
- session_start();
- if($_GET['do'] == "") {
- echo "<img src='sites/test.php'>";
- } else {
- if($_GET['do'] == $_SESSION['CaptchaImage']) {
- echo "The Captcha is correct!";
- } else {
- echo "The Captcha is incorrect!";
- }
- }
Add Comment
Please, Sign In to add comment