2010-04-22 67 views
0
<?php 
include 'lib/db_conn.php'; 
$uid=$_REQUEST['uid']; 
$pass=$_REQUEST['pass']; 
if(($uid==NULL && $pass==NULL) ||($uid==NULL) ||($pass==NULL)) 
{ 
    header("location:index.php?msg=Fields can't be left blank.."); 
} 

$pass=md5($pass); 
$sql1="SELECT * FROM `tb_user` WHERE `email`='$uid' AND `pass`='$pass'"; 
$rs1=mysql_query($sql1) or die (mysql_error()); 
$row1=mysql_fetch_array($rs1) or die (mysql_error()); 
$email=$row1['email']; 
if($uid==$email) 
{ 
     session_start(); 
     $_SESSION['id']=$row1['id']; 
     header("location:home.php"); 
} 
else 
{ 
header("location:index.php?msg=Wrong Credentials.."); 
} 
?> 
+0

'如果(($ UID == NULL && $通過== NULL)||($ UID == NULL)||( $ pass == NULL))'...是過度的。該OR情況下是指與殼體是沒有必要的 – dnagirl 2010-04-22 13:25:33

+1

'位置:'後緊跟由絕對URI,包括協議。對逃避http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html – TRiG 2010-04-22 13:39:24

回答

0

最好不要寫在地址欄的消息,但只是標記化了,即:

header("location:index.php?msg=wcred"); 

,並在index.php:

if ($_GET['msg'] == "wcred") echo "Wrong Credentials.."; 

而且,正如愷提到, $uid=$_REQUEST['uid'];必須

$uid=mysql_real_escape_string($_REQUEST['uid']); 

而且,dnagirl提到,場空虛檢查是錯誤的。
而且,我說,exit必須遵循的任何位置,頭

<?php 
if((empty($_REQUEST['uid']) OR empty($_REQUEST['pass'])) { 
    header("location:index.php?msg=fempty"); 
    exit; 
} 
include 'lib/db_conn.php'; 

$pass=md5($_REQUEST['pass']); 
$pass=mysql_real_escape_string($pass); 
$uid=mysql_real_escape_string($_REQUEST['uid']); 

$sql1="SELECT * FROM `tb_user` WHERE `email`='$uid' AND `pass`='$pass'"; 
$rs1=mysql_query($sql1) or die (mysql_error()); 
$row1=mysql_fetch_array($rs1) or trigger_error(mysql_error()); 
if($row1) { 
    session_start(); 
    $_SESSION['id']=$row1['id']; 
    header("location:home.php"); 
    exit; 
} else { 
    header("location:index.php?msg=wcred"); 
    exit; 
} 
?> 
0

您應該使用的代碼標籤。閱讀很難看。

我想你不應該鍵入「錯誤的憑據。」按原樣字母應該URL編碼。另外,您應該在發送header()-calls之後退出()執行。

順便說一句,你應該逃避$ uid或你可以得到與SQL注入的麻煩。

+0

好點 – 2010-04-22 13:22:27