PHP codes doesn't work inside HTML codes

独自空忆成欢 提交于 2019-12-12 03:26:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!