Home > Backend Development > PHP Tutorial > PHP SESSION失效有关问题 !

PHP SESSION失效有关问题 !

WBOY
Release: 2016-06-13 10:35:05
Original
1082 people have browsed it

PHP SESSION失效问题 !!!
用CI写的腾讯登陆,需要存贮openId以及accessToken,
用Ajax

JScript code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->var xmlhttp;            if (window.XMLHttpRequest)            {// code for IE7+, Firefox, Chrome, Opera, Safari              xmlhttp=new XMLHttpRequest();            }            else            {// code for IE6, IE5              xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");            }            xmlhttp.onreadystatechange=function()              {              if (xmlhttp.readyState==4 && xmlhttp.status==200)                {                        document.getElementById("myDiv").innerHTML=xmlhttp.responseText;                }              }                          if(QC.Login.check())/*QQ 登录*/            {                                        QC.Login.getMe(function(openId, accessToken){                            xmlhttp.open("GET","http://localhost/CI/index.php/SaveInfo/save_qq_openId?openId="+openId+"&accessToken="+accessToken,true);                            xmlhttp.send();                    });                                    }
Copy after login


在SaveInfo/save_qq_openId控制器下 $_SESSION['openId'] = $_GET['openId'];

然后页面跳转到另一个控制器 echo $_SESSION['openId'];

错误提示 :
A PHP Error was encountered

Severity: Notice

Message: Undefined index: openId

Filename: controllers/ShopOnSale.php

Line Number: 125

查看过 php.ini 文件 没有问题 

在另个页面标签前写了也没有用
PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?php session_id('openId');session_start();?>
Copy after login



------解决方案--------------------
if(isset($_GET['openId']))
$_SESSION['openId'] = $_GET['openId'];
------解决方案--------------------
两个页面都需要开启session_start(); ,你做了吗?

------解决方案--------------------
在SaveInfo/save_qq_openId控制器下 $_SESSION['openId'] = $_GET['openId'];
那么你在他之前 session_start() 了吗?

又,
session_id('openId');
session_start();
是错误的,请去掉
------解决方案--------------------
注意COOKIE的domain,是否跨二级域名使用。
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template