日期:2014-05-17 浏览次数:20661 次
<?php
session_start( );
require_once( "getRootDir.php" );
require_once( "../inc/config.php" );
$action = get_param( "action" );
$username = get_param( "username" );
$password = md5( get_param( "password" ) );
if ( $action == "login" )
{
$IMGVER_RandomText = $_SESSION['IMGVER_RndText'];
$otherpwd = get_param( "otherpwd" );
if ( $IMGVER_RandomText == $otherpwd )
{
$query = "select * from house_admin ";
$result = mysql_query( $query );
$row = mysql_fetch_array( $result );
if ( $row )
{
setcookie( "house_havelogin", "true", time( ) + 36000 );
setcookie( "house_username", $row['house_username'], time( ) + 36000 );
header( "Location: index.php" );
echo "<script language='javascript'>alert('登陆成功!');window.location.href='index.php';</script>";
}
else
{
echo "<script language='javascript'>alert('请正确输入用户名和密码!');window.location.href='login1.php';</script>";
exit();
}
}
else
{
echo "<script language='javascript'>alert('请正确填写验证码!');window.location.href='login1.php';</script>";
exit();
}
}
?><HTML>……略
<?php require_once( "checklogin.php" ); ?> <html>……略
<?php
if ( $_COOKIE['house_username'] == "" || empty( $_COOKIE['house_username'] ) )
{
/*这里一直会跑进来,也就是上面的cookie获取失败*/
header( "Location: login1.php" );
}
?>
setcookie( "house_havelogin", "true", time( ) + 36000 );
setcookie( "house_username", $row['house_username'], time( ) + 36000 );
print_r($_COOKIE);
//header( "Location: index.php" );
echo "<script language='javascript'>alert('登陆成功!');window.location.href='index.php';</script>";
------解决方案--------------------
上面的if先不要判断 直接 print_f($_COOKIE); 看下有什么结果 或用firecookie插件看下cookie有没有值
------解决方案--------------------
1 注释掉 header( "Location: index.php" );
2 在header( "Location: index.php" );下面添加 print_r($row);确认是否有用户信息存在
3 在index.php里面添加 echo $_COOKIE['house_username'] ;确认在COOKIE是否有数值
php.ini 内需要设置
output_buffering = on
程序自身还存在问题,如果登录正常了,那么任何人随便写用户名密码都能登录
建议在将查询的SQL加上用户名和密码2个字段进行查询