一个完整php验证码实例程序
发布:smiling 来源: PHP粉丝网 添加日期:2014-08-25 11:34:01 浏览: 评论:0
- <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.phpfensi.com/tr/xhtml1/dtd/xhtml1-transitional.dtd">
- <html lang="en-us" xml:lang="en-us" xmlns="http://www.w3.org/1999/xhtml">
- <title>login</title>
- <link rel="stylesheet" type="text/css" href="/tryit.css" />
- <script type="text/javascript">
- function getpinimg()
- {
- document.getelementbyid("pinimg").src="log_demo.php?a=pin&r=" + math.random();
- }
- </script>
- </head>
- <body>
- <form action="log_demo.php" method="get">
- <input type="hidden" name="a" value="log" />
- user:<input type="text" name="user" size="20" value="test" /><br /><br />
- password:<input type="password" name="pass" size="12" value="123456" /><br /><br />
- pincode:<input type="text" name="pin" size="8" value="" />
- <input type="button" value="getpin" onclick="getpinimg();">
- <img id="pinimg" src="log_demo.php?a=pin" onclick="getpinimg();" />
- <input type="submit" value="submit"><br />
- </form>
- </body>
- </html>
log_demo.php代码如下:
- <?php
- require_once("log_aux.php");
- if ($_get['a'] == "pin") {
- getpinimg();
- exit;
- }
- if ($_get['a'] == "log") {
- $ret = checkpincookie($_get['pin'], 300);
- if ($ret < 0) {//开源代码phpfensi.com
- echo "pin error:$ret ";
- exit;
- }
- // check user name and password.
- echo "ok..$ret ";
- if ("123xx" == 123) {
- echo "dddd ";
- }
- echo $_get['u'];
- }
log_aux.php代码如下:
- <?php
- $magic_a = "www.phpfensi.com34589";
- $magic_b = "234566***+";
- function getpincookie($pin_code)
- {
- global $magic_a;
- global $magic_b;
- $now = time();
- $client_ip = $_server['remote_addr'];
- $pin = md5($now . $client_ip . $magic_a . $pin_code . $maigc_b) . $now;
- return $pin;
- }
- function checkpincookie($pin_code_in, $timeout=300) // 5 miniuteswww.phpfensi.com
- {
- global $magic_a;
- global $magic_b;
- $pin = substr($_cookie['pin'], 0, 32);
- $time = substr($_cookie['pin'], 32);
- $now = time();
- if ($now - $time > $timeout) {
- return -100; // time_out
- }
- $pin_code_in = strtolower($pin_code_in);
- $client_ip = $_server['remote_addr'];
- $pin_2 = md5($time . $client_ip . $magic_a . $pin_code_in . $maigc_b);
- if ($pin === $pin_2) {
- return 0;
- } else {
- return -200; // pincode is error.
- }
- }
- function getpinimg()
- {
- // $rnd = rand(0, 10);
- $rnd = 0;
- $path = "./www.phpfensi.com/" . substr("00000$rnd", -4);
- for ($i = 0; $i < 4; ++$i) {
- if (__getpinimg($path)) {
- break;
- }
- }
- exit;
- }
- function __getpinimg($path)
- {
- require("$path/pinmap.php");
- $pinv = $pin[rand(0, $pin_max)];
- list ($file, $pin_code) = explode('#', $pinv);
- $filepath = "$path/$file$pin_ext";
- // output pincode image.
- $fh = fopen($filepath, "rb");
- if (!$fh) {
- return false;
- }
- $data = fread($fh, 10240); // php just read max size: 8k.
- fclose($fh);
- if (strlen($data) < 200) {
- return false;
- }
- // set cookie;
- header("content-type: image/jpeg");
- $pin_code = strtolower($pin_code);
- $pin = getpincookie($pin_code);
- setcookie("pin", $pin);
- echo $data;
- return true;
- }
Tags: PHP验证码 PHP简单示例
- 上一篇:php用户登录代码
- 下一篇:Php $_POST、$_GET防注入程序
相关文章
- ·php网页生成验证码实现程序(2014-07-30)
- ·简单实例php验证码代码(2014-08-17)
- ·PHP验证码生成与验证例子(2014-08-22)
- ·PHP验证码生成程序几种方法(2014-08-22)
- ·PHP验证码实现代码简单示例(2014-08-22)
- ·php验证码程序代码(2014-08-22)
- ·PHP验证码之Ajax验证实现方法(2014-08-22)
- ·php中文汉字验证码程序(2014-08-23)
- ·php 用户登录验证码的实现方法(2014-09-11)
- ·php jquery 验证码代码(2014-09-20)
- ·php验证码生成器(2018-08-06)
- ·一个好用的PHP验证码类实例分享(2020-08-17)
- ·PHP+javascript制作带提示的验证码源码分享(2021-01-15)
- ·php程序总是提示验证码输入有误解决方案(2021-05-07)
- ·php验证码生成代码(2021-06-26)
- ·php验证码的制作思路和实现方法(2021-06-26)
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)