Logic error, redirect to main page.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
php001
Forum Newbie
Posts: 10
Joined: Tue Jul 03, 2012 12:19 pm

Logic error, redirect to main page.

Post 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?
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Logic error, redirect to main page.

Post by social_experiment »

What happens once you click the button from the 'Login Successful' alert box?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
php001
Forum Newbie
Posts: 10
Joined: Tue Jul 03, 2012 12:19 pm

Re: Logic error, redirect to main page.

Post 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>";
}
php001
Forum Newbie
Posts: 10
Joined: Tue Jul 03, 2012 12:19 pm

Re: Logic error, redirect to main page.

Post 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!
Post Reply