2012-04-29 7 views
2

내 세션을 설정하기 위해 다음을 수행합니다. 에코가 나타나기 때문에 작동합니다. 하지만 다음 페이지 나 다른 세션으로 갈 때 세션이 없습니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까? 나는 이러한 세션 작업을 다음 얻기 위해 노력하고PHP 세션이 손실되었습니다.

$session_start(); 

if ($username==$dbusername&&$password==$dbpassword) 
    { 
     echo"<b>Login Successful</b><br><a href='systemadmin.html'><br>Click here to access the <strong>System Admin Page</strong></a>"; 
     $_session['username']=$dbusername; 
     if($username == "admin") 
     { 
      $_session['admin'] = true; 
     } 

:

<?php 
session_start(); 
if($_session['admin'] == true) 
{ 
// do nothing 
}else{ 
    header('Location: home.html') ; 
} 

?> 

업데이트 :

대문자 세션이 작동

하지만 지금은 세션 i가 logout.php를 사용하여 파괴이 arent

<?php 

session_start(); 

session_destroy(); 

header("location: home.html"); 

?> 

답변

5

$_session은 =>$_SESSION이어야합니다.

http://php.net/manual/en/reserved.variables.session.php

첫 번째 작품

있습니다 (요청 가능)는 '정상'변수를 설정 때문이다. 스크립트의 추가 실행을 방지하기 위해 리디렉션을 수행 한 후

http://php.net/manual/en/function.session-destroy.php#example-4368

<?php 
// Initialize the session. 
// If you are using session_name("something"), don't forget it now! 
session_start(); 

// Unset all of the session variables. 
$_SESSION = array(); 

// If it's desired to kill the session, also delete the session cookie. 
// Note: This will destroy the session, and not just the session data! 
if (ini_get("session.use_cookies")) { 
    $params = session_get_cookie_params(); 
    setcookie(session_name(), '', time() - 42000, 
     $params["path"], $params["domain"], 
     $params["secure"], $params["httponly"] 
    ); 
} 

// Finally, destroy the session. 
session_destroy(); 
?> 
가 Additionaly 당신은 항상 exit();을 사용해야합니다

UPDATE 세션을 파괴합니다.

+0

이 작동하지만 새 문제가 있습니다 – Anicho

+1

@Anicho 내 업데이트를 참조하십시오 – PeeHaa

+0

감사 repwhoringpeehaa – Anicho

0

슈퍼 글로벌의 이름은 대문자 인 $_SESSION입니다. 편지. 그것을 변경하고 도움이되는지 확인하십시오.

2

PHP 서버/세션/전역 변수는 대소 문자를 구분합니다. PHP의 경우 $_SESSION$_session과 같은 변수가 아니지만 영어로 보더라도 그럴 것 같습니다. 예상대로 PHP 세션 변수에 액세스하려면 $_session이 아닌 $_SESSION을 사용해야합니다.

2

exit(); header(); 사용자가 새 페이지로 리디렉션 한 직후에 스크립트가 항상 끝나는 것은 아니기 때문입니다.

관련 문제