I am trying to create a treasure hunt for a clients website - the visitors are given the URL of the login page and some clues to guess the username and password required to login and unlock the treasure.
The successful user logs in and is presented with instructions on how to claim their prize. Subsequent visitors are directed to a page informing them that they didn't quite make it on time.
The way I'm thinking of doing this relies on logging the IP of the first user to correctly input the username and password (the one and only winner). Their IP is written to a text file.
The treasure page then compares user IP with the first IP in the text file - if they match - user can proceed to collect the bounty - if not they are sent to a page informing them they arrived to late and have not won.
This is what I have written so far:
// try_your_luck.php
<form name="form" method="post" action="login.php">
<ul>
<li>User: <input type="text" size="20" name="user"></li>
<li>Pass <input type="password" size="20" name="pass"></li>
<li><input type="submit" value="Login"></li>
</ul>
</form>
// login.php
<?php
$usercorrect=blah;
$passcorrect=blah;
if ($user==$usercorrect && $pass==$passcorrect) {
$log_file = "ip.txt";
$ip = getenv('REMOTE_ADDR');
$fp = fopen("$log_file", "a");
fputs($fp, "$ip");
flock($fp, 3);
fclose($fp);
$goforth = "location: treasure.php"; // login correct - go forth and rejoice in thy treasure
header($goforth);
} elseif ($user!=$usercorrect || $pass!=$passcorrect) {
header("location: try_again.php"); // login incorrect - access denied
} else {
break;
}
?>
I only want one IP to be written to the file ip.txt - is this possible?
// treasure.php
<?php
$ip = getenv('REMOTE_ADDR');
$winner = fopen the file ip.txt and parse the ip address - any pointers?
if ($ip!=$winner) {
header("location: oh_well.php"); // user re-directed and informed that they have lost :(
elseif ($ip==$winner) {
<html>
I'm faltering a bit now.
Does this interest anyone? 😛