JS的SESSION值如何传递到PHP

去圣西罗-为尤文喝彩 2010-08-22 10:12:49
我想把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)
数据库连接错误。
...全文
334 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
zxj828282 2010-08-23
  • 打赏
  • 举报
回复
top 同游
111
hoojo 2010-08-23
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 changjay 的回复:]

JScript code

this.d199 = function() {
this.anonymusId = getCookie("anonymusid");
this.user.id = getCookie("userid");
this.user.email = getCookie("useremail");
this.user.password = getCookie("userpa……
[/Quote]
可以考虑将js客户端的cookie的传递到服务器用作session的id
stayalive 2010-08-23
  • 打赏
  • 举报
回复
不是……
$_COOKIE['userid'];
  • 打赏
  • 举报
回复

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']了呢?
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 stayalive 的回复:]
不是……
$_COOKIE['userid'];
[/Quote]

PHP里面代码
$_COOKIE['userid']=$_SESSION['userid'];
然后再session_start()?
我试了不行啊……
stayalive 2010-08-22
  • 打赏
  • 举报
回复
js是客户端的,不能处理session……

87,907

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧