2009-11-17 1 views
0
<?php 
//start the session 
mysql_connect("localhost","root",""); 

@mysql_select_db(fcs) 
    or die("Unable to select Database"); 

//check if the form has been submitted 
if(isset($_POST['submit'])){ 
    $msg=""; 

    //VALIDATE form information 
    if(empty($_POST['uname'])){ 
    $msg="Please enter your username."; 
    } 

    if(empty($_POST['upass'])){ 
    $msg .="Please enter your password."; 
    } 



    //check length of password 
    if(strlen($_POST['upass']) > 6){ 
    $msg .="Invalid password."; 
    } 

    if(empty($msg)){ 


    $sql = "SELECT uname,upass FROM administrator WHERE user ='".$_POST['uname']."'"; 
    $sql .= "AND password ='".md5($_POST['password'])."'"; 

    if(!$res = mysql_query($sql)){ 
     $msg.=mysql_error(); 
    }else{ 
     //user exists in system, set the session variables 
     if (mysql_num_rows($res) == 1) { 

     while($row = mysql_fetch_assoc($res)){ 
     // the user name and password match, 
      $_SESSION['uname'] = $row['uname']; 
      $_SESSION['upass'] = $_POST['upass']; 

      //Now go to the main page 
      header('location../admin.php'); 
     } 
     }else{ 
     $msg = "Your login details did not match"; 
     }//end numrows check 
    }//end res check 
    } 


}//end submit check 
?> 

참고 : 나는 (admin.php) 페이지를로드 할이 내가 코드를 실행하면 내가 원하는 페이지를로드하지 않고, PHP에서 관리자 로그인 코드

, 사용자가있는 경우 이름과 암호는 disply 메시지에서 다른 정확했다 :

header('Location: ../admin.php'); 

그리고이 같은 전체 절대 URL을 지정한 경우 더 나은은 다음과 같습니다 :

+0

메시지는 어디에 있고 질문은 무엇입니까? – Gumbo

+0

왜 관리자 페이지로의 리다이렉트가 반복됩니까? – Natrium

+0

이스케이프 처리되지 않은 $ _POST 변수를 MySQL 쿼리 문자열에 연결하면 엄청난 보안 문제가 발생합니다 (http://xkcd.com/327/). 최소한 PDO와 준비된 문구 사용을 고려하십시오 : http://uk.php.net/manual/en/pdo.prepared-statements.php –

답변

3

헤더-기능은 다음과 같이 사용되어야한다

header('Location: http://www.example.com/admin.php'); 
(대부분의 브라우저가 너무 상대 URL의 지원하지만)을 RFC 2616가 절대 URI로 그것을 필요로하기 때문에입니다

:

Location = "Location" ":" absoluteURI 
0

사용자의 위치 헤더가 있어야한다 :

header('Location: http://www.example.com/admin.php'); 

당신을 스크립트 상단에서 다음을 사용하여 세션을 시작해야합니다.

session_start(); 

세션 시작 코드는 $ _SESSION 변수에 액세스해야하는 모든 페이지의 시작 부분에 있어야합니다.

관련 문제