我想把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)
数据库连接错误。
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)
数据库连接错误。
解决方案 »
- position:fixed固定后怎么获取元素坐标?
- 发一个js库,控制输入文本框为可使用滚轮控制
- 想和大家讨论一正则,请进来看一!!
- 请教window.print()的问题(怎样去掉页面下面的URL)
- 100分求救一个调用问题
- 如何用javascript代码将下面的超级连接变成disabled的状态
- 请问表单元素如何删除
- 求遍历页面里所有对象的javascript
- 请问大虾,在javascript中究竟能不能直接调用本地的dll,那java applet行不行呢?记记记
- 两个.js文件中的方法是否可以互相调用?
- 求解!超链接的target无法正常转向,怎么设置?
- JavaScript图片连续滚动的问题
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']了呢?
PHP里面代码
$_COOKIE['userid']=$_SESSION['userid'];
然后再session_start()?
我试了不行啊……