Multiple Passwords / Redirects
Hey all,
I'm looking for a way to have one simple form field on a page and when a person enters a password, it redirects them to a site I decide. But the catch is I'd like to have multiple passwords and each one sends the person to a different page.
Any ideas?
Thanks.
teammatt3 posted this at 00:03 — 7th September 2007.
He has: 2,102 posts
Joined: Sep 2003
If you have php you could do something like this (name the file tmp.php)
<?php
if($_POST['submit'] == 'Go')
{
if($_POST['password'] == 'asjkld')
{
$location = \"http://example.com\";
}
elseif($_POST['password'] == 'adasd')
{
$location = \"http://webmaster-forums.net\";
}
elseif($_POST['password'] == 'asdkjw')
{
$location = \"http://google.com\";
}
else
{
$location = \"tmp.php\";
}
header(\"Location: $location\");
}
else {
<form action=\"tmp.php\" method=\"post\">
<input type=\"text\" name=\"password\" value=\"\"/>
<input type=\"submit\" value=\"Go\" name=\"submit\" />
</form>
}
?>
greg posted this at 16:28 — 16th September 2007.
He has: 1,581 posts
Joined: Nov 2005
teammatt3's example is spot on
an alternative is to name the page the same as the password
say the page your form is on is called "password_pages.php"
on password_pages.php you will have the following form:
<form method="get" action="getname.php">
<input type="text" name="password" value="">
<input type="submit" value="Go" name="submit">
</form>
user enters a password and submits, the form goes to "getname.php"
this is what "getname.php" would look like:
$page = $_GET['password']".php";
header("Location: '$page");
so if user types in your form "pagename1" the above code will make the variable "$page" equal "pagename1.php" and will send them to pagename1.php
to cover for the possibility of the page the user requested not existing, have a 404.html such as
$pagefrom = $_SERVER['HTTP_REFERER'];
if ($pagefrom == "getname.php") {echo "Sorry, incorrect password";}
else {echo "sorry page you are looking for is not on this site";}
the code isn't 100% accurate but you get the idea
I don't know what you are using it for or how secure you need it, teammatt3's example is more secure as people cant guess the password and the passwords can be changed, in my example if they know the page names of your site they know the passwords
but of course it isnt 100% secure anyway as your passwords aren't unique to each members, so they can readily be shared with friends of people who you give the password to or the rest of the internet
my example is easier for your users to remember passwords to the pages they wish to enter, again, I dont know what you are using it for so use whichever is best for your circumstance
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.