我找不到我的錯誤,我可以幫忙嗎?我正在嘗試使用cookie登錄代碼。先謝謝你!我似乎不能看到我的錯誤。我希望有人能看到我缺少的東西。這個錯誤是在第47行的某個地方,但我知道這並不意味着它就是這樣。我的代碼中意外的T_ELSE錯誤,有人能看到嗎?
<?php
if(isset($_POST['sent']) && $_POST['sent'] == "yes")
{
foreach($_POST as $field => $value)
{
if($value == "")
{
$blank_array[$field]= $value;
}
else
{
$good_data[$field]=strip_tags(trim($value));
}
}
}
if(@sizeof($blank_array) > 0)
{
$message = "<p style='color: red; margin-bottom: 0; font-weight: bold'> Error.</p>";
extract($blank_array);
extract($good_data);
include("form_log.php");
exit();
}
include("dbstuff.php");
$cxn = mysqli_connect($host,$user,$password,$database) or die ("coulnt connect");
$query = "SELECT first_name FROM customer WHERE user_name='$_POST[user_name]' AND password=md5('$_POST[password]')";
$result = mysqli_query($cxn,$query) or die ("couldnt query");
$n_row = mysqli_num_rows($result);
if($n_row < 1)
{
$message = "<p style='color: red; margin-bottom: 0; font-weight: bold'> Not found. </p>";
extract($_POST);
include("form_log.php");
exit();
}
else
{
$row=mysqli_fetch_assoc($result);
setcookie("first_name",$row['first_name']);
setcookie("auth","yes");
header("Location: secret_page_cookie.php");
}
else
{
$user_name = "";
$password = "";
include("form_log.php");
}
?>
對不起沒有縮進,但這很難縮進。第二別的去,如果(@sizeof)..
幾乎所有開發人員都使用縮進來格式化他們的代碼是有原因的。 – 2012-07-13 17:40:55
我有義務在這裏提到SQL注入攻擊和弱密碼哈希。 – Ryan 2012-07-13 17:43:01
另外,像你這樣使用'include'是你很快就會後悔的事情,在沒有打開form_log.php文件的情況下實際閱讀這段代碼中的內容是完全不可能的。看起來像一個理想的候選人轉換成我的功能! – fvu 2012-07-13 17:44:02