ajax - Android客户端如何获取php客户端验证码图片

WBOY
Release: 2016-06-06 20:49:50
Original
1110 people have browsed it

我用php写了个生成验证码和图片的文件(这个文件名为captcha.php),放在服务器端。
请问,Android客户端通过访问这个文件(通过url,如localhost/web/captcha.php)如何获取一张
验证码的图片?
php生成验证码及图片的代码如下:

<code><?php header('Content-type:image/png');
require_once './function.php';
$width=65;
$height=20;
$image=imagecreate($width,$height);

$bg_color=imagecolorallocate($image,0x33,0x66,0xFF);
imagefilledrectangle($image,0,0,$width,$height,$bg_color);
$text=random(5);
$font=5;
$x=imagesx($image)/2-strlen($text)*imagefontwidth($font)/2;
$y=imagesy($image)/2-imagefontheight($font)/2;

$fg_color=imagecolorallocate($image,0xFF,0xFF,0xFF);
imagestring($image,$font,$x,$y,$text,$fg_color);

$_COOKIE['captcha']=$text;

imagepng($image);
imagedestroy($image);?>
</code>
Copy after login
Copy after login

回复内容:

我用php写了个生成验证码和图片的文件(这个文件名为captcha.php),放在服务器端。
请问,Android客户端通过访问这个文件(通过url,如localhost/web/captcha.php)如何获取一张
验证码的图片?
php生成验证码及图片的代码如下:

<code><?php header('Content-type:image/png');
require_once './function.php';
$width=65;
$height=20;
$image=imagecreate($width,$height);

$bg_color=imagecolorallocate($image,0x33,0x66,0xFF);
imagefilledrectangle($image,0,0,$width,$height,$bg_color);
$text=random(5);
$font=5;
$x=imagesx($image)/2-strlen($text)*imagefontwidth($font)/2;
$y=imagesy($image)/2-imagefontheight($font)/2;

$fg_color=imagecolorallocate($image,0xFF,0xFF,0xFF);
imagestring($image,$font,$x,$y,$text,$fg_color);

$_COOKIE['captcha']=$text;

imagepng($image);
imagedestroy($image);?>
</code>
Copy after login
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template