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 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line