问题
I'm a beginner in PHP but i'm way off to be professional, I am making a small PHP projects such as create login and registration form in PHP and so on, and I am still working on creating Captcha security code, my code is working but I have a problem that I think is relate to Dream Weaver or it's configuration. The problem is that when I don't use any HTML tags, my PHP code work correctly but when I use HTML tags no matter where I use them, before or after the PHP code it doesn't work. I saw this link that is related to my question but didn't help.
PHP inside HTML doesn't work
any help would be appreciated!
Note that I am using EasyPHP webserver.
Here is my PHP code that creates captcha security code - "index.php":
<?php
session_start();
$_SESSION['secure'] = rand(1000,9999);
?>
<html>
<body>
<img src="genereate.php" >
</body>
</html>
<?php
echo $_SESSION['secure'];
?>
and this is my "generate.php" code:
<?php
header("Content-type: image/jpeg");
if(isset($_SESSION['secure']))
$text = $_SESSION['secure'];
$font_size = 30;
$image_width = 100;
$image_height = 20;
$image = imagecreate($image_width , $image_height);
imagecolorallocate($image , 255 , 255 , 255);
$text_color = imagecolorallocate($image , 0 , 0 , 0 );
for($x=1 ; $x<=30 ; $x++)
{
$x1 = rand(1 , 100);
$y1 = rand(1 , 100);
$x2 = rand(1 , 100);
$y2 = rand(1 , 100);
imageline($image , $x1 ,$y1 , $x2 , $y2 , $text_color);
}
imagettftext($image , $font_size , 0 , 15 , 30 , $text_color , 'font.ttf' ,![enter image description here][2]text);
imagejpeg($image);
?>
And I have attached the result below
来源:https://stackoverflow.com/questions/28416510/php-codes-doesnt-work-inside-html-codes