我想把JS判断用户登录后的session值传递到PHP页面里,用户登陆后跳转到类似index.php?id=1的页面。
JS代码如下:this.start = function() {
if(session_user) {
this.user = session_user;
this.onLoad();
} else {
this.d199();
if(this.user.email && this.user.password) {
request.send({act: "start_user", user_id: this.user.id, email: this.user.email, password: this.user.password}, this);
} else {
request.send({act: "start_anonymus", user_id: this.user.id}, this);
}
}我的PHP代码如下:session_start();
echo "session_user = ".$_SESSION["logged_user"];
if(empty($_SESSION['logged_user'])){    
        header("Location: index.php");
}
 else header("Location: index.php?id=".$_SESSION['logged_user']);到底是我的代码错了?还是这段JS并不是记录用户登陆后session值的?我得不到index.php?id=1的页面,总是提示 Warning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on 'localhost' (10048)
数据库连接错误。

解决方案 »

  1.   

    js是客户端的,不能处理session……
      

  2.   


    this.d199 = function() {
    this.anonymusId = getCookie("anonymusid");
    this.user.id = getCookie("userid");
    this.user.email = getCookie("useremail");
    this.user.password = getCookie("userpassword");
    }
    this.d200 = function() {
    setCookie("userid", this.user.id);
    setCookie("useremail", this.user.email);
    setCookie("userpassword", this.user.password);
    }
    this.start = function() {
    if(session_user) {
    this.user = session_user;
    this.onLoad();
    } else {
    this.d199();
    if(this.user.email && this.user.password) {
    request.send({act: "start_user", user_id: this.user.id, email: this.user.email, password: this.user.password}, this);
    } else {
    request.send({act: "start_anonymus", user_id: this.user.id}, this);
    JS第四行里getCookie("userid"),传到PHP里是不是就是$_SESSION['userid']了呢?
      

  3.   

    可以考虑将js客户端的cookie的传递到服务器用作session的id
      

  4.   


    PHP里面代码
    $_COOKIE['userid']=$_SESSION['userid'];
    然后再session_start()?
    我试了不行啊……