I am trying to create an captcha with an really easy calculate sum in it.
But when I try to add + , it turns into a blank box.
Question 2 and 3
Q2 : Is hat header thing really needed and usefull ?
Q3 : $font = dirName(FILE).’/font/karate/Karate.ttf’; Can someone explain me what FILE does?
This is my code :
<?php
ob_start();
session_start();
$randomnr = rand(1, 5);
$randomnr2 = rand(1, 5);
$plus = '+';
$randanswer = $randomnr + $randomnr2;
$_SESSION['randomnr2'] = md5($randanswer);
$im = imagecreatetruecolor(80, 20);
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 150, 150, 150);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 80, 25, $black);
$font = dirName(__FILE__).'/font/karate/Karate.ttf'; //wat is dit?
imagettftext($im, 15 , 7, 15, 19, $grey, $font, $randomnr);
imagettftext($im, 15 , 4 , 30, 19, $grey, $font , $plus); *PROBLEM*
imagettftext($im, 15 , 10, 50, 19, $white, $font, $randomnr2);
//prevent caching on client side:
header("Expires: Wed, 1 Jan 1997 00:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header ("Content-type: image/gif");
imagegif($im);
imagedestroy($im);
ob_end_flush;
?>
example : http://nightcore.nl/captcha/captcha.php
If you see things I absolutely may not do , please tell me and tell me what is better to use!
The Karate font you are using, has no PLUS sign as a character!
see the box with 0043: it is empty.
__FILE__is the filename and complete path of the php file now executing.dirname(__FILE__)can be replaced with__DIR__as of php 5.3.