2011-10-24 6 views
1

로그인 방법, 특히 로그인 후 일부 사용자의 다른 액세스 페이지에 대해 혼동스러워합니다. admininput.php에 직접 것 같이 내가 로그인을 해요 경우 내가 원하는 내가 user로 로그인하면php-mysql : 로그인 중 다른 액세스 페이지

  1. 관리자
  2. 사용자

:

내가 좋아하는 내 DB에서 일부 사용자 목록을 index.php으로 연결됩니다. 일부 사이트에서 스위치 케이스를 사용해야한다고 읽었습니다. 그러나, 나는 그것을 사용하는 방법에 대해 아직도 명확하지 않다.

$dbc=mysql_connect(_SRV,_ACCID,_PWD) or die(_ERROR15.": ".mysql_error()); 
$db=mysql_select_db("qdbase",$dbc) or die(_ERROR17.": ".mysql_error()); 

switch(postVar('action')) { 
     case 'submitlogin': 
       submitlogin(postVar('loguser'),postVar('logpass')); 
       mysql_close($dbc); 
       exit; 
       break; 
} 

function submitlogin($loguser,$logpass){ 
     if(isset($loguser,$logpass)){ 
       $myuser= mysql_real_escape_string($loguser); 
       $mypass= mysql_real_escape_string($logpass); 
       $sql= sprintf("SELECT * FROM admin WHERE user = '".$myuser."' AND password = '".$mypass."'", $myuser,$mypass); 
       $result = mysql_result($sql) or die (_ERROR26.": ".mysql_error()); 
       if(mysql_num_rows($result) > 0){ 
         session_register("loguser"); 
         session_register("logpass"); 

     switch $myuser{       //i dont know its correct or not 
      case 'admin': 
       header("location:input.php"); 
       break; 
      case 'user': 
       header("location:index.php"); 
       break; 
      }  
?> 
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'> 
<html xmlns='http://www.w3.org/1999/xhtml'> 
<head> 
     <META http-equiv='refresh' content='2; url=index.php'> 
</head> 
<title>Login success</title> 
<body> 
     <h1>You logged in !</h1> 
</body> 
</html> 
<?php 
    }else 
     { 
      header("location:log.php?msg=" . urlencode("Wrong Username or Password. Please retry")); 
     } 
    }else{ 
     header("location:log.php?msg=" . urlencode("Please enter some username and password")); 
    } 
} 
?> 

난이 오류가 발생했습니다 :

PHP Warning: mysql_result() expects at least 2 parameters, 1 given in /home/jeinqa/www/oqc/dolog.php on line 29 // on line 17 in this page 
+0

mysql_real_escape_string (stripsl ashes ($ loguser));'stripslashes는 여기에 필요하지 않으므로 생략해야합니다. – Johan

+0

암호를 데이터베이스에 저장하면 추기경이됩니다. SHA2 대신 소금에 절인 해시를 사용하십시오. – Johan

+0

@Johan : 좋아, 이미 삭제 했어. 하지만 내 대본에서 스위치 케이스는 어때? 로그인 페이지에 각 사용자별로 다른 액세스 권한을 부여하려면 어떻게해야합니까? – nunu

답변

2

무엇을 당신이하려고하는 대신에, 다른 후 로그인 페이지로 사용자 관리 '를 리디렉션하는 경우

header("location:index1.php"); //i want to use switch-case in this part 

당신은 뭔가가 필요합니다

switch($loguser) { 
    case "admin" : 
     header("location:input.php"); 
     break; 
    default: // this branch will run for all users other than 'admin' 
     header("location:index.php"); 

} 
+0

나는 이것을 시도했지만 index.php로 바로가는'admin'입니다. 왜? – nunu

+0

@nunu 그런 다음 $ loguser가 실제로 "admin"인지 확인하십시오. – Shaokan

+0

@Shaokan : 오류 메시지가 나타납니다. – nunu

관련 문제