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?
Logic error, redirect to main page.
Moderator: General Moderators
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: Logic error, redirect to main page.
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
Re: Logic error, redirect to main page.
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>";
}
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.
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!