Logic error, redirect to main page.
Posted: Tue Jul 03, 2012 11:48 pm
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?
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?