Ajax登录 - PHP中的cookie和会话脚本不会触发

时间:2012-08-21 17:51:41

标签: php jquery ajax

这是一个登录脚本,可以创建正确的cookie或会话,并将用户重定向到他们的帐户。除了它不会触发cookie和会话脚本之外,一切都能完美地找到。我想两者都是同样的错误。

jQuery部分:

$('#LogIn').click(function(){

var Username = $('#Username').val();

//Bunch of code that doesn't really matter to the question goes here

//Relevant part
//Check if the "Remember Me" Checkbox is checked

var rememberMe = $('input[name=checkbox]').is(':checked');
var url = "index.php?page=account";

if(rememberMe==true)
{
     $.post('cookie.php',{Username:Username},function(cookie)
     {
           //Do the cookie script
           $(location).attr('href',url);
           return true;
     }
}else
{
     $.post('session.php',{Username:Username},function(session)
     {
          //Do the session script
          $(location).attr('href',url);
          return true;
     }
}
});

PHP中的Cookie脚本:

    function cookie_token
    {
        //Here goes that function, not really important for the problem
    }
        $Username = $_POST['Username'];

        $cookie_value = cookie_token(15);
        $cookie = $Username." - ".$cookie_value;
        $query1 = mysql_query ("UPDATE users SET token='$cookie' WHERE Username='$Username'");
        setcookie('Username',$cookie,time()+60*60*24*3);

PHP中的会话脚本:

    $Username= $_POST['Username'];

    $_SESSION['Username'] = $Username;

我的问题:

  • 在PHP脚本中放置“标题”是一个错误吗?或者我应该以其他方式重定向?
  • 为什么PHP脚本不会触发?

PS:为了更容易阅读和理解,我只需要对问题/问题重要的代码。虽然,如果需要更多代码,我可以添加它。

0 个答案:

没有答案
相关问题