0

我有这个 php 脚本,它不在函数内

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

它似乎总是在这部分之后继续执行所有事情,不管 $num 是否等于 0 我已经尝试过退出(“消息”),死亡,返回等。对不起,如果这是一个愚蠢的问题哈哈

4

3 回答 3

3

您正在重定向页面。

页面中要注意的一个示例:

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

/* Make sure that code below does not get executed when we redirect. */
exit;
?>
于 2012-04-28T09:06:45.813 回答
2
$_POST[password]="";

那应该是(注意'):

$_POST['password'] = "";

该函数exit()在执行时肯定会停止执行。你的 if 条件一定有问题。

在 PHP 中,多个值“等于”为零(如果您使用==)。试着var_dump($num)看看里面到底有什么。

于 2012-04-28T09:07:50.527 回答
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";
}
于 2012-04-28T11:48:13.057 回答