我对php中的会话有很大的问题。我对php很新,所以我可能犯了一个错误。
主要问题是,会话变量未正确保存。 我写了一个重新登录的东西:
df= df[ df$status != "Open" & (df$Type) %in% c("BMW","VW","BENZ"), ]
我还会显示会话信息,以查看执行脚本后会发生什么:
<?php
if (!isset($_SESSION['user_id'])) {
echo "NOT SET";
?>
<h1>Authentifikation</h1>
<?php
if (isset($_POST['authentificate']) && $_POST['authentificate'] == 'Bestätigen') {
if(!isset($_POST['g-recaptcha-response']) || !isset($_POST['username']) || !isset($_POST['userpass'])) {
MessageHandler('Bitte korrigiere deine Angaben.', 2);
return;
}
$topl_curl = curl_init();
curl_setopt($topl_curl, CURLOPT_URL, 'https://www.google.com/recaptcha/api/siteverify');
curl_setopt($topl_curl, CURLOPT_HEADER, 0);
curl_setopt($topl_curl, CURLOPT_POST, true);
curl_setopt($topl_curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($topl_curl, CURLOPT_POSTFIELDS, http_build_query(array(
'secret' => $settings['CAPTCHA']['PRIVATE_KEY'],
'response' => $_POST['g-recaptcha-response'],
)));
curl_setopt($topl_curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($topl_curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11');
$topl_data = curl_exec($topl_curl);
$topl_info = curl_getinfo($topl_curl);
if (!$topl_info['http_code'] == 200 ) {
print_r($topl_info);
echo 'RE-Captcha ERROR';
return;
}
$jResponse = json_decode($topl_data, true);
if ($jResponse['success']) {
$result = $mysqli->query("SELECT id, login, cash, status FROM account.account WHERE login LIKE '".$mysqli->real_escape_string($_POST['username'])."' AND password = PASSWORD('".$mysqli->real_escape_string($_POST['userpass'])."') LIMIT 1");
if ($result->num_rows > 0) {
$info = $result->fetch_object();
if ($info->status == 'BLOCK' && $settings['MODE'] != 'BEFORE_START') {
MessageHandler('Dieser Account ist gesperrt.', 3);
return;
}
$_SESSION['user_id'] = $info->id;
$_SESSION['user_name'] = $info->login;
$_SESSION['user_dr'] = $info->cash;
MessageHandler('Du wurdest erfolgreich eingeloggt.', 2);
?>
<script>
setTimeout(function() {
window.location.replace("/index.php?s=login");
}, 3000);
</script>
<?php
} else {
MessageHandler('Deine Login Daten sind fehlerhaft, bitte versuche es erneut.');
}
return;
}
}
?>
<center><p>Bitte authentifizieren Sie sich indem Sie das Captcha ausfüllen.</p></center>
<form method="POST" action="?s=login">
<center><br><div class="g-recaptcha" data-sitekey="<?=$settings['CAPTCHA']['PUBLIC_KEY'] ?>"></div>
<input type="hidden" name="username" value="<?=$_POST['username']?>">
<input type="hidden" name="userpass" value="<?=$_POST['userpass']?>">
<br><input type="submit" name="authentificate" value="Bestätigen"/></center>
</form>
<?php
}
else {
if (!isset($_SESSION['user_id'])) {
echo "NOT SET";
}
?>
<?php
}
?>
显然设置已设置,但在3秒后刷新javascript后,会出现以下会话信息:
session_id: aea6434a454efb40851d035612307b25
array(3) { ["user_id"]=> string(1) "1" ["user_name"]=> string(5) "admin" ["user_dr"]=> string(6) "887992" } uid:
session.cookie_domain:
session file: /var/customers/tmp/censored//sess_aea6434a454efb40851d035612307b25
size: 59
我搜索了很多来解决这个问题,但是在stackoverflow上的每一个问题都得到了解答并没有帮助解决我的问题。
您有什么建议尝试吗? session_path设置正确..