Forum Moderators: coopster

Message Too Old, No Replies

Password Script

To link to pages

         

limbo

2:12 pm on Jan 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I use the script (canibalised) below for a simple password screen on one site to reveal clues to the next section...

However I'd like to alter it so the submit button could takes the user to one of a dozen or so pages dependant on what is entered.

So if the user entered timbuctu it would take them to

mysite.co.uk/timbuctu/

--------------------- PHP/HTML:

<?php
$password = "apassword";
if ($_POST['txtPassword']!= $password) {
?>

<h1>Login</h1>
<form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">

<p><label for="txtpassword">Password:</label>
<br /><input type="password" title="Enter your password" name="txtPassword" /></p>
<p><input type="submit" name="Submit" value="Login" /></p>
</form>

<?php
}
else {
?>
<p>'private' content</p>
<?php
}
?>

------------------

Ideally the solution would not have to refer to a database - i.e all the data is.

Anyone know how I can go about this? (I'm a dimwit at best, when using PHP)

Cheers, Limbo.

coopster

10:10 pm on Jan 16, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You want to redirect the user to a url which is the same as the password entered? Why not just offer up a bunch of a href's then? If they can key it into the text box, they could certainly key it into the address bar, but you could save them the work by placing the links in an href.

limbo

10:59 am on Jan 17, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



you want to redirect the user to a url which is the same as the password entered?

Not exactly. We want the user to be directed to a folder that corresponds to printed flyers with differing url's we have mailed to households.

This page is generic to all visitors - the 'password' will then lead them to the next geotargeted section. So each different area cannot be visible to another when/if they are on the homepage. It's convoluted.

coopster

2:15 pm on Jan 17, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Ah, I get it. Looks like good place for a switch [php.net] control structure. You could redirect based on the value entered once it passes. Not a working example, but it should get you started thinking in a possible direction:

$txtPassword = strip_tags($_POST['txtPassword']); // and any more data scrubbing ...
switch ($txtPassword)
{
case 'timbuctu':
header('http://example.co.uk/timbuctu/');
break;
case 'timbucthree':
header('http://example.co.uk/timbucthree/');
break;
default:
// an unexpected entry was made
}

Another idea here would be to load all possible values in a multi-dimensional array (or you could use a database) and edit the $txtPassword value against the array entries to see if it exists. If so, use the value associated with the key in your redirection.

limbo

4:11 pm on Jan 19, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks coopster - this is the just direction I needed pointing in.