2012-07-02 3 views
0

두 개의 개별 세션을 만들려고합니다. 하나는 사용자 인 경우이고 다른 하나는 사용자 인 경우입니다. $ type은 enum으로 저장됩니다 (작성자 또는 관리자가 될 수 있음). 하지만, 내 세션에 대한 고유 한 세션 ID를 얻지 못하고 있습니다. 나는 PHP와 MySQL을 처음 사용한다. 누군가 내 코드에서 오류가 어디 있는지 말해 줄 수 있습니다. 다음과 같이 도와주세요PHP에서 고유 한 세션 번호를 얻는 방법

<?php 
     session_start(); 
    ?> 


    <?php 
    include("dbconnect.php"); 
    $con= new dbconnect(); 
    $con->connect(); 
    //create and issue the query 
    $sql = "SELECT type FROM users WHERE username = '".$_POST["username"]."' AND password = PASSWORD('".$_POST["password"]."')"; 

    $result = mysql_query($sql); 

    //get the number of rows in the result set; should be 1 if a match 
    if (mysql_num_rows($result) == 1) { 
     $type_num=0; 
     //if authorized, get the values 
      while ($info = mysql_fetch_array($result)) { 
     $type =$info['type']; 
     } 

     if($type == "admin") 
      { 
      $_SESSION['type']=1; 
      $u = 'welcome.php'; 
      header('Location: '.$u); 
      } 
      else 
      { 
       $_SESSION['type']=$type_num; 
       $u = 'welcome.php'; 
       header('Location: '.$u); 


      } 
     } 
      else { 
      //redirect back to loginfailed.html form if not in the table 
      header("Location: loginfailed.html"); 
      exit; 
      } 
      ?> 

welcome.php은 다음과 같습니다

당신은 파일에서 호출 session_destroy() 전에 session_regenerate_id()를 사용할 필요가
<?php 
    session_start(); 
?> 

<html> 
<body> 
<h2>Welcome to SOD73.</h2> 
<? 
if($_SESSION['type']==1){ 
    echo "You are of the usertype Admin and your session id is "; 
    echo session_id(); 
    session_destroy(); 
} 
else { 
echo "You are of the usertype Author and your session id is "; 
echo session_id(); 
session_destroy(); 

} 
?> 

</body> 
</html> 
+2

당신은 아마 들어, 두 개의 서로 다른 브라우저를 사용 (또는한다 예 : 시크릿 모드 및 일반 모드의 Chrome)를 사용하여 세션을 테스트합니다. 그렇지 않으면 동일한 세션을 갖게됩니다. – DPlusV

+0

하나의 세션 하나의 세션 ID, 왜 2 개를 원하십니까? – xdazz

+0

동일한 브라우저에서 동일한 세션 ID가 나타납니다. 내가 다른 브라우저를 시도했을 때, 다른 브라우저. 그게 맞습니까? – user1479431

답변

1

welcome.php

관련 문제