PHP登录页问题,高手来帮忙。。。。。。

buhao_md 2010-08-10 03:41:18
我这登录页没用,我输入USER和PWD没有任何效果,请教各位大侠,本人菜鸟
<?php
if ($login){
$db_host="127.0.0.1:3306";
$db_user="root";
$db_psw="";
$db_name="hotel";
$connection=mysql_connect($db_host,$db_user,$db_psw)or die("选择服务器失败");
mysql_select_db($db_name,$connection)or die("选择数据库失败");

session_start();
$right_enter='0';
$query="select * from Background where user='$user_login' and pwd='$user_pass'";
$result=@mysql_query($query,$connection);
if ($user_array=@mysql_fetch_array($result)){
$user_id=$user_array[user_id];
$user_name=$user_array[user_info];
session_register("user_id");
session_register("user_name");
session_register("user_array");
if(($user_array[ticket_day]) and ($user_array[ticket_num])){
$right_enter='1';
echo "<script>alert('登录成功');window.location='index_bc.php';</script>";
}
else{
$error_message="<script>alert('您没有登录权限');window.location='Untitled-3.php';</script>";
}
}
else{
$error_message="<script>alert('用户名或密码错误,请重新登录.');window.location='Untitled-3.php';</script>";
}
}
if($logout){
session_start();
session_unregister("user_id");
session_unregister("user_name");
session_unregister("user_array");
}

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>

<body>
<p> </p>

<form name="form1" method="post" action="" >
<table width="289" border="1" cellspacing="0" cellpadding="1" bordercolor="#999999" align="center">
<tr bgcolor="#999999">
<td>
<div align="center"><font color="#FFFFFF" size="4">用户登录</font></div>
</td>
</tr>
<tr>
<td>
<table width="267" border="0" cellspacing="0" cellpadding="5" align="center">
<tr>
<td width="94">
<div align="right">用户:</div>
</td>
<td width="169">
<input type="text" name="user_login" size="16" maxlength="16" value="<?php echo $user_login; ?>">
</td>
</tr>
<tr>
<td width="94">
<div align="right">口令:</div>
</td>
<td width="169">
<input type="password" name="user_pass" size="16" maxlength="16">
</td>
</tr>
<tr>
<td colspan="2">
<div align="center">
<input type="submit" name="login" value=" 登 录 ">
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>

</body>
</html>
...全文
181 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
Dleno 2010-08-10
  • 打赏
  • 举报
回复
<?php
前不能有任何输出,你的utf-8文件,也不能保存bom头
buhao_md 2010-08-10
  • 打赏
  • 举报
回复
当我把数据库中的用户名和密码信息删除后又报错
大侠们帮帮忙吧,我加分
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at D:\APMServ5.2.6\www\htdocs\KJ\in.php:2) in D:\APMServ5.2.6\www\htdocs\KJ\in.php on line 3

Warning: Cannot modify header information - headers already sent by (output started at D:\APMServ5.2.6\www\htdocs\KJ\in.php:2) in D:\APMServ5.2.6\www\htdocs\KJ\in.php on line 18
PHP code
<?php
session_start();//这行报错
$db_host="127.0.0.1:3306";
$db_user="root";
$db_psw="";
$db_name="hotel";
$connection=mysql_connect($db_host,$db_user,$db_psw)or die("选择服务器失败");
mysql_select_db($db_name,$connection)or die("选择数据库失败");
mysql_query("set names 'utf8'");

$user_login=$_POST["user_login"];
$user_pass=$_POST["user_pass"];
$query="select * from Background where user='".$user_login."' and pwd='".$user_pass."'";
if($res=mysql_query($query,$connection)){
$_SESSION['user_login']=$user_login;
$_SESSION['user_pass']=$user_pass;
header('location:index_bc.htm');//这行报错
}else{
echo "<script>alert('用户名或密码不正确');</script>";
}
?>
Dleno 2010-08-10
  • 打赏
  • 举报
回复
你那个帖子给你讲了
buhao_md 2010-08-10
  • 打赏
  • 举报
回复
$user_login=$_POST["user_login"];
$user_pass=$_POST["user_pass"];
$query="select * from Background where user='".$user_login."' and pwd='".$user_pass."'";
if($res=mysql_query($query,$connection))
{
$_SESSION['user_login']=$user_login;
$_SESSION['user_pass']=$user_pass;
header('location:index_bc.php'); //就是这行
}
else
{
echo "<script>alert('用户名或密码不正确');</script>";
}
buhao_md 2010-08-10
  • 打赏
  • 举报
回复
我这行怎么会报错呢
$user_login=$_POST["user_login"];
$user_pass=$_POST["user_pass"];
$query="select * from Background where user='".$user_login."' and pwd='".$user_pass."'";
if($res=mysql_query($query,$connection))
{
$_SESSION['user_login']=$user_login;
$_SESSION['user_pass']=$user_pass;
header('location:index_bc.php');
}
else
{
echo "<script>alert('用户名或密码不正确');</script>";
}
Dleno 2010-08-10
  • 打赏
  • 举报
回复

<?php
session_save_path(dirname(__FILE__).'/');
session_start();
foreach($_POST as $_key=>$_value){
!ereg("^\_",$_key) && !isset($$_key) && $$_key=$_POST[$_key];
}
foreach($_GET as $_key=>$_value){
!ereg("^\_",$_key) && !isset($$_key) && $$_key=$_GET[$_key];
}
if ($action=="login"){
$db_host="127.0.0.1:3306";
$db_user="root";
$db_psw="";
$db_name="hotel";
$connection=mysql_connect($db_host,$db_user,$db_psw)or die("选择服务器失败");
mysql_select_db($db_name,$connection)or die("选择数据库失败");

$right_enter='0';
$query="select * from Background where user='$user_login' and pwd='$user_pass'";
$result=@mysql_query($query,$connection);
if ($user_array=@mysql_fetch_array($result)){
$user_id=$user_array['user_id'];
$user_name=$user_array['user_info'];
$_SESSION["user_id"]=$user_id;
$_SESSION["user_name"]=$user_name;
$_SESSION["user_array"]=$user_array;
if($user_array['ticket_day'] && $user_array['ticket_num']){
$error_message="<script>alert('登录成功');window.location='index_bc.php';</script>";
}else{
$error_message="<script>alert('您没有登录权限');window.location='Untitled-3.php';</script>";
}
}else{
$error_message="<script>alert('用户名或密码错误,请重新登录.');window.location='Untitled-3.php';</script>";
}
echo $error_message;exit;
}elseif($action=="logout"){
isset($_SESSION["user_id"]) && unset($_SESSION["user_id"]);
isset($_SESSION["user_name"]) && unset($_SESSION["user_name"]);
isset($_SESSION["user_array"]) && unset($_SESSION["user_array"]);
}else{
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>

<body>
<p> </p>

<form name="form1" method="post" action="" >
<table width="289" border="1" cellspacing="0" cellpadding="1" bordercolor="#999999" align="center">
<tr bgcolor="#999999">
<td>
<div align="center"><font color="#FFFFFF" size="4">用户登录</font></div>
</td>
</tr>
<tr>
<td>
<table width="267" border="0" cellspacing="0" cellpadding="5" align="center">
<tr>
<td width="94">
<div align="right">用户:</div>
</td>
<td width="169">
<input type="text" name="user_login" size="16" maxlength="16" value="<?php echo $user_login; ?>">
</td>
</tr>
<tr>
<td width="94">
<div align="right">口令:</div>
</td>
<td width="169">
<input type="password" name="user_pass" size="16" maxlength="16">
</td>
</tr>
<tr>
<td colspan="2">
<div align="center">
<input type="hidden" name="action" value="login">
<input type="submit" name="submit" value=" 登 录 ">
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
<?php
}
?>
buhao_md 2010-08-10
  • 打赏
  • 举报
回复
<?php
session_start();
?>
<?php
include("lianjie.php");
foreach($_POST as $_key=>$_value){
!ereg("^\_",$_key) && !isset($$_key) && $$_key=$_POST[$_key];
}
foreach($_GET as $_key=>$_value){
!ereg("^\_",$_key) && !isset($$_key) && $$_key=$_GET[$_key];
}

if ($login){
$user_login=$_POST["user"];
$user_pass=$_POST["pwd"];

$right_enter='0';
$query="select * from Background where user='$user_login' and pwd='$user_pass'";
$result=@mysql_query($query,$connection);
echo "<script>alert('登录成功.');window.location='index_bc.php';</script>";
}
else{
echo "<script>alert('用户名或密码错误,请重新登录.');window.location='Untitled-3.php';</script>";
}
?>
buhao_md 2010-08-10
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 dingsongtao 的回复:]
引用 1 楼 amani11 的回复:

register_globals = On//这个是On么?

+++++

你似乎都还没把php最基本的搞明白

php.ini里开启了register_globals = On

那么你的程序里才可以直接用post/get传递过来的变量。

否则你只能用$_POST['post传递过来的变量名']/$_GET['get传递过来的……
[/Quote]
还是不行没有反应
Dleno 2010-08-10
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 amani11 的回复:]

register_globals = On//这个是On么?
[/Quote]
+++++

你似乎都还没把php最基本的搞明白

php.ini里开启了register_globals = On

那么你的程序里才可以直接用post/get传递过来的变量。

否则你只能用$_POST['post传递过来的变量名']/$_GET['get传递过来的变量名']
或者在你页面前加上:

foreach($_POST as $_key=>$_value){
!ereg("^\_",$_key) && !isset($$_key) && $$_key=$_POST[$_key];
}
foreach($_GET as $_key=>$_value){
!ereg("^\_",$_key) && !isset($$_key) && $$_key=$_GET[$_key];
}

那你后面的也能直接使用了
CodeBus 2010-08-10
  • 打赏
  • 举报
回复

$login = isset($_POST['login']) ? TRUE : FALSE;
buhao_md 2010-08-10
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 amani11 的回复:]
引用 2 楼 buhao_md 的回复:

引用 1 楼 amani11 的回复:
register_globals = On//这个是On么?

我只要求能正常登录,登陆后跳转到其他页面。
并且在其他页面中获取登录的用户名



如果这个不打开,你前面的变量是取不到值的,不会执行if里的代码片段


要么你把取值方式改了

$_POST['……']
[/Quote]
if ($login){
$db_host="127.0.0.1:3306";
$db_user="root";
$db_psw="";
$db_name="hotel";
$connection=mysql_connect($db_host,$db_user,$db_psw)or die("选择服务器失败");
mysql_select_db($db_name,$connection)or die("选择数据库失败");
$user_login=$_POST["user"];
$user_pass=$_POST["pwd"];
session_start();
// $right_enter='0';
$query="select * from Background where user='$user_login' and pwd='$user_pass'";
$result=@mysql_query($query,$connection);

/*if ($user_array=@mysql_fetch_array($result)){
$user_id=$user_array[user_id];
$user_name=$user_array[user_info];
session_register("user_id");
session_register("user_name");
session_register("user_array");
if(($user_array[ticket_day]) and ($user_array[ticket_num])){
$right_enter='1';
echo "<script>alert('登录成功');window.location='index_bc.php';</script>";
}
else{
$error_message="<script>alert('您没有登录权限');window.location='Untitled-3.php';</script>";
}
}
else{
$error_message="<script>alert('用户名或密码错误,请重新登录.');window.location='Untitled-3.php';</script>";
}*/

这样也不行
amani11 2010-08-10
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 buhao_md 的回复:]

引用 1 楼 amani11 的回复:
register_globals = On//这个是On么?

我只要求能正常登录,登陆后跳转到其他页面。
并且在其他页面中获取登录的用户名
[/Quote]


如果这个不打开,你前面的变量是取不到值的,不会执行if里的代码片段


要么你把取值方式改了

$_POST['……']
huaxing211 2010-08-10
  • 打赏
  • 举报
回复
0 O 应该有区别吧……
buhao_md 2010-08-10
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 amani11 的回复:]
register_globals = On//这个是On么?
[/Quote]
我只要求能正常登录,登陆后跳转到其他页面。
并且在其他页面中获取登录的用户名
amani11 2010-08-10
  • 打赏
  • 举报
回复
register_globals = On//这个是On么?

4,250

社区成员

发帖
与我相关
我的任务
社区描述
国内外优秀PHP框架讨论学习
社区管理员
  • Framework
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧