1 <?php 2 session_start(); 3 if (isset($_SESSION['triedTimes'])) 4 $_SESSION['triedTimes'] = $_SESSION['triedTimes'] + 1; 5 else 6 $_SESSION['triedTimes'] = 1; 7 8 $username = $password = "aaaa"; 9 10 if ($_SERVER['PHP_AUTH_USER'] == $username && $_SERVER['PHP_AUTH_PW'] == $password){ 11 echo "Auth dialog behavior when press OK button: "; 12 if ($_SESSION['triedTimes'] == 5) 13 echo "<span style='color:green'>PASS</span>"; 14 else 15 echo "<span style='color:red'>FAIL</span>"; 16 exit; 17 } else { 18 header('WWW-Authenticate: Basic realm="My Realm"'); 19 header('HTTP/1.0 401 Unauthorized'); 20 echo "Auth dialog behavior when press Cancel button: "; 21 if ($_SESSION['triedTimes'] == 1) 22 echo "<span style='color:green'>PASS</span>"; 23 else 24 echo "<span style='color:red'>FAIL</span>"; 25 exit; 26 } 27 ?> 28