[英]Redirect to page only once?
I have this piece of php code that looks up the account prompt function on my website. 我有这段php代码,可在我的网站上查找帐户提示功能。 basically if a user has violated a term and condition on the site, at login they are redirected to a prompt page that says you are very naughty and here's a warning.
基本上,如果用户违反了网站上的条款和条件,则在登录时会将他们重定向到提示页面,提示您非常顽皮,这是警告。
My code is this: 我的代码是这样的:
<?php
$account_prompt = account_prompt();
while ($prompt = mysql_fetch_array($account_prompt))
if ($prompt['account_prompt'] == '1') {
redirect_to("prompt.php");
}
?>
My question is how can i get it to only redirect once? 我的问题是我如何才能使其仅重定向一次? Thanks
谢谢
He just redirects 1ce unless you are stucked in an endless loop... 除非您陷入无限循环,否则他只会重定向1ce。
Try this 尝试这个
if (isset($prompt['account_prompt']) && $prompt['account_prompt'] == '1') {
header("Location: prompt.php");
exit;
}
Use a flag which is set to 1 according to your condition, and take the redirect out of the loop. 使用根据您的条件设置为1的标志,并将重定向移出循环。
$flag = 0;
while ($prompt = mysql_fetch_array($account_prompt)) {
if ($prompt['account_prompt'] == '1') $flag = 1;
}
if ($flag == 1)
redirect_to("prompt.php");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.