Page 1 of 1

Logic error, redirect to main page.

Posted: Tue Jul 03, 2012 11:48 pm
by php001
I have three files which are main_login.php, checklogin.php and login_success.php. I have some logic error, let see the errors below......

The code below is in the checklogin.php. I typed the right username and password and it pop up Login Successfully, that's means the "if" statement can be run, but why can't redirect to the login_success.php?

if($count==1){
// Register $username, $password and redirect to file "login_success.php"
//session_register("username");
$_SESSION['username'] = null;
//session_register("password");
$_SESSION['password'] = null;
echo "<script language='javascript'>alert('Login Successfully!')</script>";
echo "<script language='javascript'>window.location='login_success.php'</script>";

}
else {
echo "<script language='javascript'>alert('Wrong Username or Password!')</script>";
echo "<script language='javascript'>window.location='main_login.php'</script>";
}

<?php
session_start();
if(!session_is_registered(username)){
header("location:main_login.php");
}
session_register('admin');
include ("connect.php");
$userName = $_SESSION['admin'];

if($_SESSION['admin']!= null)
{
?>
<html>
...
...
...
</html>

<?php //invalid login(need space between <"?php" and "//invalid login")
}
else
{
echo "<script language='javascript'>alert ('Invalid login')</script>";
echo "<script language='javascript'>window.location='login.php'</script>";
}
?>

Is that the red line code problems? What should I do? Any suggestion?

Re: Logic error, redirect to main page.

Posted: Wed Jul 04, 2012 5:23 am
by social_experiment
What happens once you click the button from the 'Login Successful' alert box?

Re: Logic error, redirect to main page.

Posted: Wed Jul 04, 2012 8:21 am
by php001
After I typed the username and password, it will pop out the "Login Successfully" message. If the login_successfully message can pop out, then why can't link to the login_success.php page?
if($count==1){
// Register $username, $password and redirect to file "login_success.php"
//session_register("username");
$_SESSION['username'] = null;
//session_register("password");
$_SESSION['password'] = null;
echo "<script language='javascript'>alert('Login Successfully!')</script>";
echo "<script language='javascript'>window.location='login_success.php'</script>";
}

Re: Logic error, redirect to main page.

Posted: Wed Jul 04, 2012 8:25 am
by php001
Finally, the problem is solved. Is because of the variable from the login_success.php can't get the variable. My friends help me to solved this problem, thank you!