View Full Version : Code Redirector
blanejmc
05-06-2012, 05:24 PM
Hiya,
Im looking for something that is an input box where you put in a code and it redirects you to a site:
e.g.
If I enter 666666 it will redirect you to adress.com/666666
and if I enter 777777 it will redirect to address.com/777777
But if i enter an unknown code it says Incorrect Passcode.
Thanks in advance.
James
Your question is unclear.
Please provide more information, and be as specific as possible.
What do you want to accomplish? What have you already tried? What problems did you encounter?
Also, please be sure that you have included all relevant code and/or a link to the page in question.I assume is this for a webpage?
what programming language are you using?
how are you entering the "code" (via a form)?
do you want to redirect to local pages, or to other websites?
djr33
05-06-2012, 11:31 PM
There's a Javascript 'password' script here on DD that does all of that. The only thing it doesn't do is tell you if the password is wrong (it'll just send you to a non-existent page).
keyboard
05-06-2012, 11:37 PM
Here's a quick example of how it could be done (if I undersand your question correctly)
Javascript (Not Secure)
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
var acceptedPass=new Array(); // THESE ARE THE LIST OF ACCEPTED PASS CODES
acceptedPass[0]="666666";
acceptedPass[1]="777777";
// DON'T EDIT AFTER HERE
function checkPass() {
var i = 0;
var check = 0;
var passInput = document.getElementById('pass');
var AL = acceptedPass.length;
for (i=0;i<AL;i++) {
if(acceptedPass[i] == passInput.value) {
check = 1;
}
}
if(check == 1) {
window.location = passInput.value;
} else {
alert("Wrong Passcode");
}
}
</script>
</head>
<body>
Password <input type="text" id="pass" /> <input type="button" value="Submit" onclick="checkPass()" />
</body>
</html>
Php (Secure)
<?php
if(isset($_POST['submit1'])) {
$acceptedPass[0]="666666"; // THESE ARE THE LIST OF ACCEPTED PASS CODES
$acceptedPass[1]="777777";
// DON'T EDIT AFTER HERE
$pass = mysql_real_escape_string($_POST['pass']);
$AL = count($acceptedPass);
$check = 0;
for ($counter = 0; $counter < $AL; $counter += 1) {
if($acceptedPass[$counter] == $pass) {
$check = 1;
}
}
if($check == 1) {
header('Location:' . $pass);
} else {
echo "Wrong Passcode";
echo '<input type="button" value="Back" onclick="history.back()">';
}
} else {
?>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form action="" method="post">
Password <input type="text" name="pass" /> <input type="submit" name="submit1" value="Submit" />
</form>
</body>
</html>
<?php
}
?>
If this wasn't what you wanted, please clarify what you meant (like traq said)
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.