1

我有这段 php 代码可以在我的网站上查找帐户提示功能。基本上,如果用户违反了网站上的条款和条件,在登录时他们会被重定向到一个提示页面,上面说你很顽皮,这里有一个警告。

我的代码是这样的:

 <?php

$account_prompt = account_prompt();
while ($prompt = mysql_fetch_array($account_prompt)) 


 if ($prompt['account_prompt'] == '1')  {
    redirect_to("prompt.php"); 
 }
 ?>

我的问题是我怎样才能让它只重定向一次?谢谢

4

2 回答 2

1

除非您陷入无限循环,否则他只会重定向 1ce...

尝试这个

if (isset($prompt['account_prompt']) && $prompt['account_prompt'] == '1')  {
    header("Location: prompt.php"); 
    exit;
}
于 2012-11-05T03:55:22.187 回答
0

根据您的条件使用设置为 1 的标志,并将重定向移出循环。

           $flag = 0;
           while ($prompt = mysql_fetch_array($account_prompt))  {


                if ($prompt['account_prompt'] == '1') $flag = 1;
            }

            if ($flag == 1)
                  redirect_to("prompt.php"); 
于 2012-11-05T03:56:30.810 回答