R
Rick
Guest
this is php for a simple login script. But no matter which user logs in they always go to the home page. It seems the $page[$i] is not working. I suspect the problem is that the i variable is not stored past the for loop. How do I fix this... sorry I'm a complete newbie to this
<?php
$usernames = array("user1", "user2", "user3", "superman");
$passwords = array("pass1", "pass2", "pass3", "superman");
$page = array("home.html","rescues.html","servicearea.html","thecompany.html");
for($i=0;$i<count($usernames);$i++){
$logindata[$usernames[$i]]=$passwords[$i];
}
if($logindata[$_POST["username"]]==$_POST["password"]){
session_start();
$_SESSION["username"]=$_POST["username"];
header('Location: '.$page[$i]);
exit;
}else{
header('Location: login.php?wrong=1');
exit;
}
?>
<?php
$usernames = array("user1", "user2", "user3", "superman");
$passwords = array("pass1", "pass2", "pass3", "superman");
$page = array("home.html","rescues.html","servicearea.html","thecompany.html");
for($i=0;$i<count($usernames);$i++){
$logindata[$usernames[$i]]=$passwords[$i];
}
if($logindata[$_POST["username"]]==$_POST["password"]){
session_start();
$_SESSION["username"]=$_POST["username"];
header('Location: '.$page[$i]);
exit;
}else{
header('Location: login.php?wrong=1');
exit;
}
?>