여기 여기 내 index.php를PHP 세션이 예상대로 작동하지 않습니다. 어떻게 해결합니까?
<?php
session_start();
if($_SESSION['authorizedreferral'] == false){ //login.php sets 'authorizedreferral' to false, and redirects to here. That way, login.php can't be accessed directly.
session_destroy(); //destroy the session, so the 'authorizedreferral' session is revaluated each time.
echo "<h1>No ticky, no washy!</h1>"; //Sorry, don't pass go, and don't collect $200
}elseif(!isset($_COOKIE['loggedin'])){ //if there isn't a 'loggedin' cookie set, forward to the login.php page
$_SESSION['authorizedreferral'] = true; //yes, this is a correct referral. Otherwise, login.php will kick you out!
header("Location: login.php"); //forward to login.php
exit; //need this for some reason?
}
?>
입니다 login.php입니다 : 여기
<?php
session_start(); //start the session
if(!isset($_SESSION['authorizedreferral'])){ //if 'authorizedreferral' isn't set (i.e. someone just loads login.php directly)
$_SESSION['authorizedreferral'] = false; //set 'authorizedreferral' to false - they aren't allowed here!
header('Location: http://'.$_SERVER["HTTP_HOST"]); //and ship 'em back home!
exit; //need this for some reason
}
?>
이 가능한 상황입니다
- 사용자가 index.php를 간다 - 그들이 피난처 이후 로그인하지 않았습니다 (로그인 쿠키가 없습니다). 로그인을 위해 login.php 페이지로 전송됩니다.
- 사용자가 login.php에 직접 액세스하려고합니다. 사용자가 index.php로 다시 전송되고 "No Ticky, no washy!"라는 메시지가 나타납니다.
그러나 지금은 사용자가 항상 "No Ticky, No Washy!" index.php 페이지에 접근 할 때. 내가 뭘 놓치고 있니?
는 http://webify.nitrouscloud.net
굉장 -'==='또는 기본 세션 설정에 대해 알지 못했습니다. 매우 도움이된다! – Jared