- 論壇徽章:
- 0
|
原帖由 xhy701 于 2006-4-29 12:40 發(fā)表
誰有做過php 驗(yàn)證碼程序?要復(fù)雜一點(diǎn)的,難識別一點(diǎn)的,有沒有給共享下的?謝謝!
我做的你可以看看效果
http://pwc.casc.com.cn
代碼:
登錄界面
index.html
###########################################################
<html>
<head>
<title>login</title>
<style type="text/css">
<!--
.textbox {
height: 18px;
width: 100px;
}
.text {
font-size: 14px;
vertical-align: bottom;
color: #0000FF;
}
.style1 {
font-size: 18px;
color: #0000FF;
font-family: "幼圓";
}
-->
</style>
</head>
<body>
<table width="200">
<tr><td align="center" valign="bottom" class="style1" bgcolor="#C7D3F9">請輸入用戶名和密碼</td>
</tr>
</table>
<form method="post" action="login.php">
<table width="200" border="0" bgcolor="C7D3F9">
<tr>
<td width="97" class="text">用戶名:</td>
<td width="144" align="right" valign="bottom"><input type="text" name="user" class="textbox"></td>
</tr>
<tr>
<td class="text">密碼:</td>
<td align="right" valign="bottom"><input type="password" name="passwd" class="textbox"></td>
</tr>
<tr>
<td class="text">驗(yàn)證碼:</td>
<td align="right" valign="bottom"><input type="text" name="auth" class="textbox"></td>
</tr>
</table>
<img src="ttt.php?act=yes" align="middle">
<table width="200"><tr><td align="right"><input type="button" value="看不清楚驗(yàn)證碼" onclick="window.location.reload();"><input name="submit" type="submit" value="Submit"></td></tr></table>
</form>
</body>
</html>
生成驗(yàn)證碼程序
ttt.php
###########################################################
<?
if($_GET['act'] == "yes"
{
header('Content-type: image/gif');
$im = imagecreate(60,1 ;
//$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
$chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
$str_a = $chars{mt_rand(0,35)}; //區(qū)分大小寫的值為mt_rand(0,61)
$str_b = $chars{mt_rand(0,35)};
$str_c = $chars{mt_rand(0,35)};
$str_d = $chars{mt_rand(0,35)};
$string = $str_a.$str_b.$str_c.$str_d;
$bg = imagecolorallocate($im, 250, 250, 159);
$font_color = imagecolorallocate($im, mt_rand(0,150),mt_rand(0,150),mt_rand(0,150));
imagestring($im, mt_rand(3,5), mt_rand(0,5), mt_rand(0,5), $str_a, $font_color);
imagestring($im, mt_rand(3,5), mt_rand(15,25), mt_rand(0,5), $str_b, $font_color);
imagestring($im, mt_rand(3,5), mt_rand(30,40), mt_rand(0,5), $str_c, $font_color);
imagestring($im, mt_rand(3,5), mt_rand(45,50), mt_rand(0,5), $str_d, $font_color);
for ($i=1; $i<=15; $i++)
{
imagestring($im,mt_rand(0,5),mt_rand(-5,63),mt_rand(-5,23),".",imageColorAllocate($im,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255)));
}
imagegif($im);
session_start();
$_SESSION['auth'] = $string;
}
?>
驗(yàn)證程序
login.php
###########################################################
<?php
session_start();
$name = $_POST['user'];
$password = $_POST['passwd'];
$auth = $_POST['auth'];
require("db.php" ;
$db = new db();
$sql = "select * from user where name = '$name' and password = '$password'";
$result = $db->query($sql);
if($data = mysql_fetch_object($result) > 0 and $_SESSION['auth'] == $auth)
{
$_SESSION['user'] = $name;
$_SESSION['passwd'] = $password;
header("Location: main.php" ;
}else
{
print '
<script language=javascript>
alert("登錄失敗,請重新登錄!" ;
self.window.location="index.html";
</script>';
}
?> |
|