2014-01-13 2 views
-5

로그인 스크립트를 만들고 있습니다. 헤더는 모두 작동하지만 분명히 $ _SESSION은 비어 있습니다. 이 사람이 왜 이런지 알 수 있습니까?

$db = dbConnection(); 

// username and password sent from form 
$myusername= $_POST['myusername']; 
$mypassword= md5($_POST['mypassword']); 

// To protect MySQL injection (more detail about MySQL injection) 
$myusername = stripslashes($myusername); 
$mypassword = stripslashes($mypassword); 
$myusername = mysql_real_escape_string($myusername); 
$mypassword = mysql_real_escape_string($mypassword); 
$sql="SELECT * FROM " .$members. " WHERE BINARY `username`= '".$myusername."' and BINARY `password`= '".$mypassword."'"; 
$result = $db->query($sql); 

// Mysql_num_row is counting table row 
$count=$result->rowCount(); 

// Fetch this accounts row from db 
$row = $result->fetch(PDO::FETCH_ASSOC); 

// If result matched $myusername and $mypassword, table row must be 1 row 
if($count==1){ 

$_SESSION['username'] = $myusername; 
$_SESSION['privileges'] = $row['privileges']; 
$_SESSION['email'] = $row['email']; 
header("location:index.php"); 

}

+2

'session_start();가 어딘가에 숨겨져 있다고 가정하십니까? –

답변

4

는 스크립트의 상단에 session_start()를 추가합니다.

+0

10 회 중 9 번, OP가 돌아 서서 "내 연결 파일에 있습니다"라고 말합니다. 나는 이런 질문에 결코 대답하지 않는다. 그것들은'C.O.W.' 코드 범주에 속합니다. –

+0

session_start(); 헤더가있는 index.php에서 호출됩니다. 그러나 $ _SESSION 변수를 실제로 설정하기 전에 호출해야합니다. 답변 해주셔서 감사합니다. – aardnoot

+0

3 초 전에 내가 그것을 썼다, OP가 나오고 내가 말한 것을 씁니다. 알고 있었어. –

1

여기서 두 가지 가능성은 session_start();이 사용되지 않았거나 $ count가 1과 같지 않을 수 있습니다. 둘 다 누락 될 수 있습니다.

관련 문제