<?php
  
include "../../config.php";
  if(
$_GET['view_source']) view_source();
?><html>
<head>
<title>Challenge 8</title>
<style type="text/css">
body { background:black; color:white; font-size:10pt; }
</style>
</head>
<body>
<br><br>
<center>
<?php
$agent
=trim(getenv("HTTP_USER_AGENT"));
$ip=$_SERVER['REMOTE_ADDR'];
if(
preg_match("/from/i",$agent)){
  echo(
"<br>Access Denied!<br><br>");
  echo(
htmlspecialchars($agent));
  exit();
}
$db dbconnect();
$count_ck mysqli_fetch_array(mysqli_query($db,"select count(id) from chall8"));
if(
$count_ck[0] >= 70){ mysqli_query($db,"delete from chall8"); }

$result mysqli_query($db,"select id from chall8 where agent='".addslashes($_SERVER['HTTP_USER_AGENT'])."'");
$ck mysqli_fetch_array($result);

if(
$ck){
  echo 
"hi <b>".htmlentities($ck[0])."</b><p>";
  if(
$ck[0]=="admin"){
    
mysqli_query($db,"delete from chall8");
    
solve(8);
  }
}

if(!
$ck){
  
$q=mysqli_query($db,"insert into chall8(agent,ip,id) values('{$agent}','{$ip}','guest')") or die("query error");
  echo(
"<br><br>done!  ({$count_ck[0]}/70)");
}
?>
<a href=./?view_source=1>view-source</a>
</body>
</html>