<?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을 지정한 경우 더 나은은 다음과 같습니다 :
메시지는 어디에 있고 질문은 무엇입니까? – Gumbo
왜 관리자 페이지로의 리다이렉트가 반복됩니까? – Natrium
이스케이프 처리되지 않은 $ _POST 변수를 MySQL 쿼리 문자열에 연결하면 엄청난 보안 문제가 발생합니다 (http://xkcd.com/327/). 최소한 PDO와 준비된 문구 사용을 고려하십시오 : http://uk.php.net/manual/en/pdo.prepared-statements.php –