<?php
session_start();
Header("Content-type: image/PNG");
//生成验证码图片
$img = imagecreate(44,18);
$background = ImageColorAllocate($img, 245,245,245);
imagefill($img,0,0,$background); //背景
srand((double)microtime()*1000000);
//生成4位数字
for($i=0;$i<4;$i++){
$font = ImageColorAllocate($img, rand(100,255),rand(0,100),rand(100,255));
$authnum=rand(1,9);
$vcodes.=$authnum;
imagestring($im, 5, 2+$i*10, 1, $authnum, $font);
}
for($i=0;$i<100;$i++) //加入干扰象素
{
$randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));
imagesetpixel($img, rand()%70 , rand()%30 , $randcolor);
}
ImagePNG($img);
ImageDestroy($img);
$_SESSION['VCODE'] = $vcodes;
?>
调用
<img src="/verify.php" align="absmiddle" /> 用include就好 <head>
<title>网页</title>
</head>
<body>
<script>
function change(str){
if(str=="device")
location.reload()
else if(str=="macid")
document.getElementById("devices").innerHTML='<input id="device" name="device" type="text" value="" class="int"/>';
}
</script>
<form action="?" id="commentform" method="post" class="edit">
<h2 class="tab">查询</h2>
<ul>
<li><select name="type"onChange="change(this.value);"><option value='device' selected>帐号</option><option value='macid'>地址</option>
</select>:<span id="devices"><input id="device" name="device" type="text" value=""onkeyup="value=value.replace(/[^\d]/g,'') "onbeforepaste="clipboardData.setData
('text',clipboardData.getData('text').replace(/[^\d]/g,''))" class="int"/></span></li>
<img src="/verify.php" align="absmiddle" />
<li class="all_ok"><input type="submit" class="btn_b" value="确定"/></li>
</ul>
</form>
<?
if($_POST['device']!=="")
{
if($_POST['type']=="macid")
{
$exec="select * from device where macid='".$_POST['device']."'";
$msg="地址";
}
else
{
$exec="select * from device where device='".$_POST['device']."'";
$msg="账号";
}
?>
<?
$conn=mysql_connect ("127.0.0.1", "root", "123456");
mysql_select_db("device");
mysql_query("set names utf8");
$result=mysql_query($exec);
if(!mysql_num_rows($result))
echo "此条".$msg."不存在!";
while($rs=mysql_fetch_object($result))
{
?>
<table style="width:500px; border:1px #d2d2d2 solid;">
<tr style="background:#cccccc;height:23px;"><td>账号</td>< td>密码</td><td>MAC</td>
<tr class="registerErrors" style="color:#333;height:20px;">
<td><? echo $rs->DEVICE_NAME ?></td>
<td><? echo $rs->DEVICE_PASSWORD ?></td>
<td><? echo $rs->macid ?></td>
</tr>
</tr>
</table>
<?
}
}
else
echo "账号或地址不能为空!"
?>
</body>
</html>
你试下
[ Edited bysokoo on 2011-3-11 15:30 ] SQL语句中的$_POST['device']
改成$_POST试试
[ Edited by点苍老妖 on 2011-3-11 20:15 ]
页:
[1]