Php Can';不创建会话
首先,您应该尝试设置虚拟数据以测试会话是否正常工作。就在您的Php Can';不创建会话,php,json,session,Php,Json,Session,首先,您应该尝试设置虚拟数据以测试会话是否正常工作。就在您的会话\u start()之后 <?php ob_start(); session_start(); require ('openid.php'); function logout() { echo '<form action="logout.php" method="post"><button class="btn btn-danger" type="submit
会话\u start()之后
<?php
ob_start();
session_start();
require ('openid.php');
function logout() {
echo '<form action="logout.php" method="post"><button class="btn btn-danger" type="submit"><i class="fa fa-power-off"></i> Log Out</button></form>'; //logout button
}
function steamlogin() {
try {
require("settings.php");
$openid = new LightOpenID($domain);
if(!$openid->mode) {
if(isset($_GET['login'])) {
$openid->identity = 'http://steamcommunity.com/openid';
header('Location: ' . $openid->authUrl());
}
return "<form action=\"?login\" method=\"post\"> <input type=\"image\" src=\"http://cdn.steamcommunity.com/public/images/signinthroughsteam/sits_large_noborder.png\"></form>";
}
elseif($openid->mode == 'cancel') {
echo 'User has canceled authentication!';
} else {
if($openid->validate()) {
$id = $openid->identity;
$ptn = "/^http:\/\/steamcommunity\.com\/openid\/id\/(7[0-9]{15,25}+)$/";
preg_match($ptn, $id, $matches);
$steamid = $matches[1];
$link = file_get_contents("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=".$key."&steamids=".$steamid."");
$decode = json_decode($link);
$newlink = $decode->response->players->profileurl;
$xml = simplexml_load_file($newlink."?xml=1");
@$custom = $xml->customURL;
if(strlen($custom) <= 4){
$user = $xml->steamID64;
} else {
$user = $custom;
}
$_SESSION['steamid'] = $user;
//Determine the return to page. We substract "login&"" to remove the login var from the URL.
//"file.php?login&foo=bar" would become "file.php?foo=bar"
$returnTo = str_replace('login&', '', $_GET['openid_return_to']);
//If it didn't change anything, it means that there's no additionals vars, so remove the login var so that we don't get redirected to Steam over and over.
if($returnTo === $_GET['openid_return_to']) $returnTo = str_replace('?login', '', $_GET['openid_return_to']);
header('Location: '.$returnTo);
} else {
echo "User is not logged in.\n";
}
}
} catch(ErrorException $e) {
echo $e->getMessage();
}
}
如果该键在整个请求中都不存在,则表示会话处理程序存在问题(可能缺少写入权限)
如果您的会话正在工作,那么您就开始沿着逻辑树往下走,检查每个If语句中的表达式,看看执行路径是什么,您没有提供任何当前输出,因此我无法立即判断
这不是一个确定的答案,但我相信如果你听从我的建议,你会找到问题的根源。你是否使用了session_start()?在开发和测试时不要使用@
来抑制错误。您想看到错误。是的。包含后的第一行…请向我们显示文件的其余部分,但我的最佳选择是:在其中一个includes@usandfriends不仅在开发过程中,您不应该抑制错误。@GeorgeCristian会话不起作用的原因有很多。到目前为止,最常见的问题是IMO缺乏写入权限。请通过session_save_path()或php.ini查找存储会话的位置,并检查其权限。其他原因可能包括浏览器中禁用cookie、试图跨域共享会话、cookie路径错误等等。
$_SESSION['test'] = 'test';
var_dump($_SESSION);