如何编写以基本身份验证形式计算用户输入并在第三次之后重定向到另一页的用户的php代码?因此,算法必须像这样:
如果按取消,则回显“ <h1>Authorization Required</h1>
”;
session_start();
if(isset($_SESSION['login_attempts'])){ $_SESSION['login_attempts']++; }else{$_SESSION['login_attempts'] = 1;}
if($_SESSION['login_attempts'] == 3 && $login_failed == true){
header('Location: http://www.example.com');
die;
}
$_user = 'test1324546';
$_password = 'test23456';
if ($_SERVER['PHP_AUTH_USER'] != $_user|| $_SERVER['PHP_AUTH_PW'] != $_password ) {
header('WWW-Authenticate: Basic realm="hi"');
header('HTTP/1.0 401 Unauthorized');
echo "<html><head><title>401 Authorization Required</title></head><body>";
echo "<h1>Authorization Required</h1>";
exit;
} else {
}
?>
那是对的吗?
使用会话将是最简单的方法,但这不会阻止bot,因为它们会清除其会话cookie。
这是一些示例代码。
<?php
session_start();
$_user = 'test1324546';
$_password = 'test23456';
if ($_SERVER['PHP_AUTH_USER'] != $_user || $_SERVER['PHP_AUTH_PW'] != $_password ) {
if(isset($_SESSION['login_attempts'])){ $_SESSION['login_attempts']++; }else{$_SESSION['login_attempts'] = 1;}
if($_SESSION['login_attempts'] == 3){
header('Location: http://www.example.com');
exit;
} else {
header('WWW-Authenticate: Basic realm="hi"');
header('HTTP/1.0 401 Unauthorized');
echo "<html><head><title>401 Authorization Required</title></head><body>";
echo "<h1>Authorization Required</h1>";
exit;
}
} else {
header('Location: /page1.php');
exit;
}
?>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句