2012-04-28 55 views
0

我有這樣的PHP腳本它不是一個功能exit()不起作用?

$num = mysql_num_rows($result); 
if ($num == 0) 
{ 
    header("Location:index.php#captcha");//Location:#errorlogin.html"); 
    $_POST[password]=""; 
    exit; 
} 

它似乎總是繼續這一部分後執行的一切,無論$ NUM等於0我已經嘗試過退出(「信息」),模具內,回報等。對不起,如果這是一個noobish問題哈哈

回答

4

你是redirecting的頁面。

一個例子,從this頁面發現:

<?php 
header("Location: http://www.example.com/"); /* Redirect browser */ 

/* Make sure that code below does not get executed when we redirect. */ 
exit; 
?> 
2
$_POST[password]=""; 

這也許應該是(注意'):

$_POST['password'] = ""; 

功能exit()被執行時,它絕對停止執行。你的條件肯定有問題。

在PHP中,多個值「相等」爲零(如果使用==)。試試var_dump($num)看看那裏真的有什麼。

+0

vardump returns int(1)does not really sense ... – Madmadmax 2012-04-28 15:03:56

+0

@Madmadmax _does_有道理。在這種情況下,if條件將爲false,因此'exit()'不會被執行。 – svens 2012-04-30 09:50:07

2

exit不會工作,因爲它是有2個依賴

A. if ($num == 0)如果$num不是零退出是行不通的

B. header("Location:index.php#captcha");如果您的位置退出工作不會麥汁

$num = mysql_num_rows ($result); 
if ($num == 0) { 
    $_POST ['password'] = null; 
    header ("Location: http://yoursite.com/index.php#captcha"); // Location:#errorlogin.html"); 
    exit(); 
} 
else 
{ 
    echo "Found $num in the database"; 
}