PDA

View Full Version : PHP form redirect



Valor Studios
02-06-2008, 09:38 PM
Basically I wanna set up a form where the user is required to enter in a username and a password. It then searches for any criteria (in php code) that matches. For example if the username is "name" and password is "1234", if this statement is met, then it redirects to a certain folder. I haven't worked with php much but in C++ its a couple lines of code and fairly simple. I was hoping someone can help me here. The idea of this being, where the redirection occurs, the folder is protected by .htaccess and the user then enters in another pass/username. I know how to set up .htaccess but just need help with php.

Seems like if and else statements. I don't know whether or not php has switch statements or something of this sort...:confused::(

james438
02-07-2008, 12:23 AM
I know this is not quite what you are looking for, but it is a start.

www.mysite.com/login1.php has this:

<form action='http://www.mysite.com/login2.php' method='POST'><p><br>
<input type='password' name='pasword' value='ee'>
<input type='submit' value='Go to Next Page'>
</form>
www.mysite.com/login2.php has this
<?php
session_start();
$pasword=$_POST['pasword'];
$_SESSION['pasword'] = "$pasword";
if ( @$_SESSION['pasword'] != "secret" )
{
header("location: login1.php");
exit();
}else header("location: http://www.mysite.com/private/index.php");
?>
The protected pages have this code at the beginning of the page
<?php
session_start();
if ( @$_SESSION['pasword'] != "secret" )
{
header("location: ../login1.php");
exit();
}

This version uses one password only. It can be modified to use other passwords as well or multiple ones depending on your needs. Another version could get the info from a database, which sounds to me more along the lines of what you are wanting to do although as I am the only person on my site in need of logging in I use the above script and I use the .htaccess files as well for added protection.

Valor Studios
02-08-2008, 09:13 PM
Thanks alot. I also found another interesting plugin for wordpress so I might use WP for CMS but thanks alot. I think i'm gonna implant the code you gave me and if later on I want to upgrade, i'll use WP.