<?php
if(isset($_POST['usename'])) {
if($_POST['username'] == 'a' && $_POST['password'] == 'b') {
header("Location: 1.php");
exit();
}else
echo "请输入正确的用户名和口令";
}
?>
<form method="post">
用户名<input type=text name=username>
口令<input type=password name=password>
<input type=submit>
</form>
if(isset($_POST['usename'])) {
if($_POST['username'] == 'a' && $_POST['password'] == 'b') {
header("Location: 1.php");
exit();
}else
echo "请输入正确的用户名和口令";
}
?>
<form method="post">
用户名<input type=text name=username>
口令<input type=password name=password>
<input type=submit>
</form>
运行后出现一下问题。
1,用户名密码输正确后没有任何反映(也就是没有执行 1.php)。
2,用户名密码输入错误后也没有任何反映。我的环境 php4.3.4 apache 2.0.48
我看了php4 的帮助,上面写着
要是在 PHP 的配置文件中,track_vars 设为 On 时,直接使用变量名字就好了
我在php.ini 文件中找不到 设置track_vars 的地方,
谢谢高手帮忙。
if(isset($_POST['usename'])) {
if($_POST['username'] == 'a' && $_POST['password'] == 'b') {
header("Location: 1.php");
exit();
}else
echo "请输入正确的用户名和口令";
}
?>
<form method="post" action="<?= $PHP_SELF ?>">
用户名<input type=text name=username>
口令<input type=password name=password>
<input type=submit>
</form>
按下确定按钮后没有任何反映,既没有弹出警告信息,也没有打开1.php文件。
请教到底是为什么啊?
ok.php 代码如下
-----------------------------------
<?php
if(isset($_POST['usename'])) {
if($_POST['username'] == 'a' && $_POST['password'] == 'b') {
header("Location: 1.php");
exit();
}else
echo "请输入正确的用户名和口令";
}
?>
<form method="post" action="<?= $PHP_SELF ?>">
用户名<input type=text name=username>
口令<input type=password name=password>
<input type=submit>
</form>
1.php 代码如下:
----------------------------------------------------
<?
info()
?>我的环境 php4.3.4 apache 2.0.48
===============================
<?php
if(isset($Submit))
{ if(isset($User)&&($User=="a")&&isset($Passwd)&&($Passwd=="b"))
{ header("Location:./l.php"); }
else
{ print"<script language=\"JavaScript\">\n";
print" alert(\"输入的用户名和密码不正确!\\n请重新登录……\");\n";
print"</script>\n";
}
}
?>
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>登录权限认证</title>
</head>
<body>
<form method="POST" action="auth.php">
<div align="center">
<center>
<table border="0" cellspacing="1" width="30%" height="121">
<tr>
<td width="100%" align="center" colspan="2" height="28">登录权限认证</td>
</tr>
<tr>
<td width="50%" align="right" height="25">用户:</td>
<td width="50%" align="center" height="25"><input type="text" name="User" size="20"></td>
</tr>
<tr>
<td width="50%" align="right" height="25">密码:</td>
<td width="50%" align="center" height="25"><input type="password" name="Passwd" size="20"></td>
</tr>
<tr>
<td width="100%" align="center" colspan="2" height="27">
<input type="submit" value="提交" name="Submit">
<input type="reset" value="重写" name="Reset">
</td>
</tr>
</table>
</center>
</div>
</form>
</body>
</html>
-----------------------------------
<?php
if(isset($_POST['login'])) {
if(isset($_POST['username'])&&$_POST['username']=='a'&&isset($_POST['password'])&&$_POST['password']=='b') {
header("Location: 1.php");
exit();
}else
echo "请输入正确的用户名和口令";
}
?>
<form method="post" action="<?= $PHP_SELF ?>">
用户名<input type=text name=username>
口令<input type=password name=password>
<input type=submit name=login>
</form>
不过这么多的代码,只有: ustb(偶然) 的最后发表的才是正确的,其他高手发表的都
不能正确运行。不过在下还有一个小小的请求,就是怎么和mysql 联系起来用户登陆认证。
mysql的脚本大致如下:
mysql_connect('localhost:3306','root','');
mysql_select_db("test");
test 库里有一test表, 内容如下 user pass
a b谢谢高手们的帮助,待会揭帖。
if(isset($_POST['usename'])) {
这一行中的变量是“usename”
而表单输入的一行
<input type=text name=username>
变量名是username
看出来问题了么?
function db_connect()
{
$conn=mysql_connect('localhost:3306','root','');;
if(!$conn)
{
return false;
}
$conn=mysql_select_db("test");
if(!$conn)
{
return false;
}
return $conn;
}
function login($username,$password)
{
$conn=db_connect();
if(!$conn)
{
return false;
}
$query="select * from test where user = '$username' and pass = password('$password')";
$result=mysql_query($query);
if(!$result)
{
return false;
}
if(mysql_num_rows($result)>0)
{
return true;
}
else
{
return false;
}
}
if(isset($_POST['username'])) {
if(login($username,$password)) {
header("Location: 1.php");
exit();
}else
echo "请输入正确的用户名和口令";
}
?>
<html>
<head>
<title></title>
</head>
<body>
<form method="post" action="<?= $PHP_SELF ?>">
用户名<input type=text name=username>
口令<input type=password name=password>
<input type=submit>
</form>
</body>
</html>
<?
if(isset($_POST['usename'])) {
if($_POST['username'] == 'a' && $_POST['password'] == 'b') {
header("Location: 1.php");
exit();
}else
echo "用户名和口令不正确!";
}
?>
<form method="post">
用户名<input type=text name=username>
口令<input type=password name=password>
<input type=submit>
</form>
if(isset($_POST['usename'])) {
if($_POST['username'] == 'a' && $_POST['password'] == 'b') {
header("Location: 1.php");
exit();
}else
echo "用户名和口令不正确!";
}
?>
<form method="post">
用户名<input type=text name=username>
口令<input type=password name=password>
<input type=submit>
</form>
mysql_select_db("test");
$sql = "select * from test where user='$username'";
$result = mysql_query($sql);
$row = mysql_fetch_rows($result);
if($row[pass]==$password){
header("Location: 1.php");
exit();
}else{
echo "你的用户名和口令不正确";
}
?>
<form method="post" action="<?= $PHP_SELF ?>" onSubmit="check()">
用户名<input type=text name=username>
口令<input type=password name=password>
<input type=submit name=login value=login>
</form>
<script>
function check()
{
if(document.username.value=="" || document.password.value==""){
alert("请输入完整信息");
}
}
</script>
-----------------------------------
<?php
mysql_connect('localhost:3306','root','');
mysql_select_db("test");if(isset($_POST['login']))
{
if(isset($_POST['username'])&&!empty($_POST['username'])&&isset($_POST['password'])&&!empty($_POST['password']))
{
//假设你的字段名为username和password且密码以明文存放
$sql = "SELECT COUNT(*) AS rcnt FROM test WHERE username='".$_POST['username']."' AND password='".$_POST['password']."'";
$res = @mysql_query($sql);
$arr = @mysql_fetch_array($res);
$num = $arr['rcnt'];
if($num==1)
{
header("Location: 1.php");
exit();
}
else
{
echo "没有匹配的用户名和口令";
}
}
else
{
echo "请输入正确的用户名和口令";
}
}
?>
<form method="post" action="<?= $PHP_SELF ?>">
用户名<input type=text name=username>
口令<input type=password name=password>
<input type=submit name=login>
</form>
不过仔细测试以后,发现又只有ustb(偶然) ( ) 的代码是正确的,其他的或多或少
都存在问题,不过给了我不同的启迪思维,非常感谢大家。
等一下一定揭帖,谢谢大家
你看看啦,一个注册系统