如何编写 php 代码来计算用户以基本身份验证形式输入并在第三次重定向到另一个页面后?所以必须是这样的算法:
- 如果登录错误 3 次,则转到 example.com
- 如果登录正确,请访问 host.com/page1.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 { } ?>
那是对的吗?