Wamp Server不在html标签内的页面上显示图像?

时间:2014-01-25 13:46:08

标签: php html image wamp

为什么这在wamp服务器上工作正常:

<?php 
 //Let's generate a totally random string using md5 
    $md5_hash = md5(rand(0,999)); 
    //We don't need a 32 character long string so we trim it down to 5 
    $security_code = substr($md5_hash, 15, 5); 

    //Set the session to store the security code
    $_SESSION['security_code'] = $security_code;

    //Set the image width and height 
//    $im = imagecreate(97, 18);
    $im= @imagecreate(97, 18)
        or die("Cannot Initialize new GD image stream");

    //white background and blue text
    $bg = imagecolorallocate($im, 255, 255, 255);
    $textcolor = imagecolorallocate($im, 167, 167, 167);

    //Add randomly generated string in white to the image

    imagestring($im, 5, 27, 1, $security_code, $textcolor); 


    //Tell the browser what kind of file is come in 
    header("Content-Type: image/png"); 


    //Output the newly created image in jpeg format 
    imagepng($im); 

    //Free up resources
    imagedestroy($im); 
?>

但是,这不起作用(只需添加html标签)?

<html>
<body>
<?php 
 //Let's generate a totally random string using md5 
    $md5_hash = md5(rand(0,999)); 
    //We don't need a 32 character long string so we trim it down to 5 
    $security_code = substr($md5_hash, 15, 5); 

    //Set the session to store the security code
    $_SESSION['security_code'] = $security_code;

    //Set the image width and height 
//    $im = imagecreate(97, 18);
    $im= @imagecreate(97, 18)
        or die("Cannot Initialize new GD image stream");

    //white background and blue text
    $bg = imagecolorallocate($im, 255, 255, 255);
    $textcolor = imagecolorallocate($im, 167, 167, 167);

    //Add randomly generated string in white to the image

    imagestring($im, 5, 27, 1, $security_code, $textcolor); 


    //Tell the browser what kind of file is come in 
    header("Content-Type: image/png"); 


    //Output the newly created image in jpeg format 
    imagepng($im); 

    //Free up resources
    imagedestroy($im); 
?>
</body>
</html>

你能告诉我为什么内部的html标签php代码在WAMP服务器上不起作用,但只有php代码可以正常工作吗?

0 个答案:

没有答案