问题描述:

I have created an iframe in HTML like:

<p class="input-block">

<iframe src="php/image.php" height="50" width="100" scrolling="no" frameborder="0" marginheight="0" marginwidth="0" class="captcha-frame" name="captcha_image_frame"></iframe>

</p>

this html file is located under inetpub/wwwroot/Site, and there is a image.php file under inetpub/wwwroot/Site/php. However, when I enter the html page, I see the error on console:

GET http://demo.com/php/image.php 404 (Not Found)

If I chance src to "http://localhost/php/image.php", then I get the error:

GET http://localhost/php/image.php net::ERR_CONNECTION_REFUSED

Note: When I enter http://demo.com/php/image.php, I get not found error as well, but I expect not to get it since there is a image.php under php folder:(

The question is, how can I manage to assign image.php to the iframe source. I appreciate if anyone helps.

Thanks!

*demo is not the original domain.

Edit:

image.php content:

<?php

session_start();

header("(anti-spam-content-type:) image/png");

$enc_num = rand(0, 9999);

$key_num = rand(0, 16);

$hash_string = substr(md5($enc_num), $key_num, 5);

$hash_md5 = md5($hash_string);

$_SESSION['verify'] = $hash_md5;

// Verification Image Background Selection

$bgs = array('1.png');

$background = array_rand($bgs, 1);

// Verification Image Variables

$img_handle = imagecreatefrompng($bgs[$background]);

$text_colour = imagecolorallocate($img_handle, 255, 255, 255);

$font_size = 5;

$size_array = getimagesize($bgs[$background]);

$img_w = $size_array[0];

$img_h = $size_array[1];

$horiz = round(($img_w / 2) - ((strlen($hash_string) * imagefontwidth(5)) / 2), 1);

$vert = round(($img_h / 2) - (imagefontheight($font_size) / 2));

// Make the Verification Image

imagestring($img_handle, $font_size, $horiz, $vert, $hash_string, $text_colour);

imagepng($img_handle);

// Destroy the Image to keep Server Space

imagedestroy($img_handle);

网友答案:

The error you are getting is because port 80 is using by some other application. This link will help you. If Skype running, change Skype settings and reinstall server.

So to show a captcha, I do this way, by converting image to data URL.in html instead of iframe, directly use img tag

<img src="./php/image.php" />

in php as follows

<?php
header ('Content-type: image/png');
$im = @imagecreatefrompng("./1.png"); 
imagepng($im, NULL, 0);
imagedestroy($im);
?>
相关阅读:
Top