douzhenao6515 2013-01-09 17:54
浏览 63
已采纳

jQuery移动登录,php,cookie无效

I'm building web app aas my major project for degree. Simple login was working but now I'm trying to implement cookies and my script is not working for some reason. I need to find out why, but can't do for last 2h. Here is my question:

From login form variables are passed into my login script (no security for password or jql injection was implemented so far), when I press login errors comes up, "Error Loading Page", this is login script:

session_start();

$username = $_GET["name"];
$password = $_GET["password"];
$remember_me = $_GET['remember_me'];

include('mysql_connection.php');
mysql_select_db("jzperson_imesUsers", $con);

$res1 = mysql_query("SELECT * FROM temp_login WHERE username='$username' AND password='$password'");
$count1=mysql_num_rows($res1);

if(isset($_COOKIE['usr_IMes']) && isset($_COOKIE['psw_IMes'])){
                    $user_n = $_COOKIE['usr_IMes'];
                    $pasw_n = $_COOKIE['psw_IMes'];

                    $res2 = mysql_query("SELECT * FROM temp_login WHERE username='$user_n' AND password='$pasw_n'");
                    $count2=mysql_num_rows($res2);

                    if($count2 == 1){

                                    $_SESSION['username'] = $user_n;

                                    header('Location: http://imes,jzpersonal.com/userpanel.php');

                    }else {
                                    setcookie('usr_IMes', $user_n, time() - 31*24*60*60);
                            setcookie('psw_IMes', $pasw_n, time() - 31*24*60*60);

                                    header('Location: http://imes,jzpersonal.com/index.html');
                    }

}else{

if($count1==1){
    $_SESSION['username'] = $username;

    if(isset($remember_me)){

setcookie('usr_IMes', $username, time() + 30*24*60*60);
setcookie('psw_IMes', $password, time() + 30*24*60*60);

header("Location: http://imes.jzpersonal.com/userpanel.php");
    }else{      

      header("Location: http://imes.jzpersonal.com/userpanel.php");

   }
}else{
    $login = "failed";
}
}

Can anyone see problem in my script? In login part? If not here is my authentication script on the start of every page, maybe my error is there:

session_start();

if(isset($_COOKIE['usr_IMes']) && isset($_COOKIE['psw_IMes'])){
                    $user_n = $_COOKIE['usr_IMes'];
                    $pasw_n = $_COOKIE['psw_IMes'];

                    $res2 = mysql_query("SELECT * FROM temp_login WHERE username='$user_n' AND password='$pasw_n'");
                    $count2=mysql_num_rows($res2);

                    if($count2 == 1){
                                    header('Location: http://imes,jzpersonal.com/userpanel.php');   
                    }else {
                                    setcookie('usr_IMes', $user_n, time() - 31*24*60*60);
                            setcookie('psw_IMes', $pasw_n, time() - 31*24*60*60);

                                    header('Location: http://imes,jzpersonal.com/index.html');
                    }

}else{

if(!isset($_SESSION['username']))
{
header('Location: http://imes.jzpersonal.com/index.html');
}

if(empty($_SESSION['username']))
{
header('Location: http://imes.jzpersonal.com/index.html');
}
}

Hope some error will be found, thank you for all your help.

  • 写回答

1条回答 默认 最新

  • dqj5046 2013-01-09 21:03
    关注

    The redirect is a bad url: http://imes,jzpersonal.com/userpanel.php - this would give you your "error loading page". Besides that, you should NEVER store username/password in cookies - it is a terrible practice because cookies can be viewed on the machine. Also, you are using the original PHP MySQL API which is deprecated - you should be using PDO or mysqli.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集