怎样给HTML/PHP网页增加密码验证

自己做了个网站,PHP+MYSQL的
不支持ASP等动态..
想达成以下效果:
打开网页 首页为密码输入页(index.html).
输入密码后点确定转到密码自动验证页(login.php)
验证正确后转入指定网页(in.html)
不正确后转入报错网页(error.html)
请把index.html和login.php的代码发下
用不用到数据库都行 最好不用到
感谢啊~
我说的不是验证码啊...就是一个自行设定的密码..
还有.2L 代码应该放在那里?
<body></body>里?
还有..只要密码就够了
用户名就不用了

第1个回答  推荐于2017-12-15
很简单 密码为123456 你可以在login.php里面改

index.html 将以下代码放入 <body></body>里面就可以
<form method="post" action="login.php">
密码: <input type="password" name="password"/><br>
<input type="submit" name="submit" value="登陆">
</form>

login.php 完整的login.php内容
<?php
$password = isset($_POST['password']) ? $_POST['password'] : '';
if($password == '123456'){
echo "<script>alert('登陆成功。');location.href='in.html';</script>";
//不需要提示 则把 alert('登陆成功。'); 删除掉
}else{
echo "<script>alert('密码错误 登陆失败。。');location.href='error.html';</script>";
//不需要提示 则去掉 同上
}
?>

OK 了 简单吧。本回答被提问者采纳
第2个回答  2010-07-15
checkImg.php
<?php
//生成验证码图片
session_start();
Header("Content-type: image/png");
srand((double)microtime()*1000000);
$im = imagecreate(45,18);//设置图片的宽与高
$black = ImageColorAllocate($im, 58,75,242);//设置背景颜色
$white = ImageColorAllocate($im, 255,255,255);//设置文字颜色
$gray = ImageColorAllocate($im, 200,200,200);//干扰颜色
imagefill($im,45,18,$gray);

while(($chk_num=rand()%10000)<1000);
$_SESSION["chk_num"] = $chk_num;
//将四位整数验证码绘入图片
imagestring($im, 5, 5, 1,$chk_num , $white);//5, 5, 1分别表示为字体大小,左边距,上边距
for($i=0;$i<100;$i++) //加入干扰象素
{
imagesetpixel($im, rand()%70 , rand()%30 , $gray);
}
ImagePNG($im);
ImageDestroy($im);
?>

html页面增加验证码图片
<img id="img1" src="checkImg.php" alt="看不清?点击更换" onclick="this.src=this.src+'?'" style="margin-top: 5px;" />

前提还需要你打开GD扩展
打开php.ini文件
将extension=php_gd2.dll前面的;去掉
第3个回答  2010-07-15
login.php
<?
session_save_path("./");
session_start();
$pwd=$_POST['pwd'];
$user=$_POST['user'];
$define_user="用户名";//设定的用户名
$define_pwd="密码";//设定的密码
if($login_submit){
if($user!=$define_user)$str="您的用户名错误!";
else{
if($pwd!=$define_pwd) $str="您的密码错误!";
else{
session_register("ses_user");
$ses_user="用户名";
header("location:index.php");
}
}
}
?>
<html>
<head><title>进入验证</title>
</head>
<style>
table{font-size:9pt;}
</style>
<body><br>
<form name="form1" method="post" action=<?echo $PHP_SELF ?> >
<table border="0" cellpadding="3" cellspacing="1" align="center" width="300" bgcolor="#3399CC">
<tr height="25" bgcolor="#E7E7E7"><td colspan="2"><b>XXXXXX--</b>进入验证</td></tr>
<tr height="25" bgcolor="#e7f7f7" ><td align="right">用户:</td><td><input type="text" name="user"></td></tr>
<tr height="25" bgcolor="#e7f7f7" ><td align="right">密码:</td><td><input type="text" name="pwd"></td></tr>
<tr height="25" bgcolor="#e7f7f7" ><td></td><td><input type="submit" name="login_submit" value="提交"><?echo "<font color=red>".$str."</font>";?></td></tr>
</table>
</form>

index.php

<?
session_save_path("./");
session_start();
if(!session_is_registered("ses_user")) header("location:login.php");//这里也可以判断答案是否正确来处理
//下面是你要加的内容
///
///
?>
验证通过,进入了主页了
第4个回答  2010-07-15
index.html页

<form method="post" action="login.php">
<input type="text" name="user" value=""/><br>
<input type="text" name="password" value=""/>

</form>

login.php页

$user = isset ($_POST['user']) ? $_POST['user']:"";
$password = isset ($_POST['password ']) ? $_POST['password ']:"";
if ($user == "admin" and $password == "123"){
header("Location: in.html ");
}
else{
header("Location: error.html ");
}

index.html 放在<body> </body>里面

login.php 放到<?php ?>里面
相似回答