我正在通过我编写的 createCaptcha 函数创建一个 Captcha 会话。在网络服务中,我调用此函数来创建验证码会话和图像,然后我想发送验证码图像或通过网络服务显示创建的验证码图像,用户可以通过网络服务发送它的值,但我面临错误。实际上,当我通过 Firefox 附加组件soap_client 对其进行测试时,我得到了一个编码结果,而不是指向该图像的链接。
知道我哪里错了吗?
验证码功能码:
<?php
session_start();
function createcaptcha($imgname)
{
/* Attempt to open */
$im = @imagecreatefromjpeg($imgname);
/* See if it failed */
if(!$im)
{
/* Create a black image */
$code=rand(1000,9999);
$_SESSION["code"]=$code;
$im = imagecreatetruecolor(50, 24);
$bg = imagecolorallocate($im, 22, 86, 165);
$fg = imagecolorallocate($im, 255, 255, 255);
imagefill($im, 0, 0, $bg);
/* Output an captcha code */
imagestring($im, 5, 5, 5, $code, $fg);
}
return $im;
}
GetCaptcha 肥皂类:
session_start();
include_once('captcha.php');
class getCaptcha extends DBM
{
public function getcaptcha()
{
//creating and generating captcha image and code
$img = createcaptcha('captcha.png');
//encoding to base64
//$base64 = base64_encode($img);
$path = $img;
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
$save = "/captchafile/captcha.png";
imagepng($base64, $save);
$captcha=$save;
$this->strResult = "";
$this->strResult.="<captcha>";
$this->strResult.="<captcha>$captcha</captcha>";
$this->strResult.="</captcha>";
}
function __toString()
{
if($this->strResult!=""){
return $this->strResult;
}
return "";
}
}