Sigh.
Nobody actually posts code! D:
Chrishirst is right, JS can be disabled, so I'd recommend using the PHP one, but the JS one is slightly faster.
PHP: Untested, should work, though.
HTML Code:
<?php
$userAge = $_POST['userAge'];
$errorPage = "error.php";
$secretPage = "secret.php";
if (isset($userAge)&&$userAge>18) {
header("Location: $secretPage");
}
else if (isset($userAge)&&$userAge<18) {
header("Location: $errorPage");
}
else {
echo <<<AuthForm
<form action="" method="post">
Enter your age:
<input type="text" name="userAge" />
<input type="submit" value="Submit" />
</form>
AuthForm;
}
?>
JS: (Tested, works)
HTML Code:
<script type="text/javascript">
function Auth() {
if (userAge.value>18) {
window.location = "secret.html";
}
else {
window.location = "error.html";
}
}
</script>
<input type="text" id="userAge" name="userAge" />Enter your age
<input type="button" onclick="Auth()" value="Authenticate" />
OR If you want them to actually enter the word 'secret' as a password...
PHP: Untested, should work, though.
HTML Code:
<?php
$passcode = $_POST['passcode'];
$errorPage = "error.php";
$secretPage = "secret.php";
if (isset($passcode)&&$passcode=="SECRET") {
header("Location: $secretPage");
}
else if (isset($passcode)&&$passcode!="SECRET") {
header("Location: $errorPage");
}
else {
echo <<<AuthForm
<form action="" method="post">
Enter Password
<input type="text" name="passcode" />
<input type="submit" value="Submit" />
</form>
AuthForm;
}
?>
JS: (Tested, works)
HTML Code:
<script type="text/javascript">
function Auth() {
if (passcode.value=="SECRET") {
window.location = "secret.html";
}
else {
window.location = "error.html";
}
}
</script>
<input type="password" id="passcode" name="passcode" />Enter Password
<input type="button" onclick="Auth()" value="Authenticate" />
If you want I can make it so that even if they type in 'SeCRet' it will work, easily.
Just combine the two to get the outcome you want.
If the user's age is greater than 18, then display the 'secret' one. Simple. I can do it for you, too, if you can't do that yourself 
Last edited by Physicsguy; 06-23-2010 at 10:34 AM..
|