i have a very simple login script. There are still some errors that I cant figure out: this is my code <?php session_start(); ?> <html> <head> <title> Logging In </title><script type="text/javascript"> <!-- function delayer(){ window.location = "main.php" } //--> </script> </head> <body onLoad="setTimeout('delayer()', 5000)" bgcolor="blue"><center><font size="36"><b><br> Logging in, please wait. If your browser does not auto matically redirect you, <a href="main.php">click here</a>. </font></center> </body> </html> <?php //get input data $user=$_POST["username"]; $pass=$_POST["password"]; //encrypt username and pass $cuser=md5($user); $cpass=md5($pass); //make variables $ip = $_SERVER['REMOTE_ADDR']; $userplusip = $user . $ip; //include login file include($user . ".php"); //make sure info matches and starts session if ($cuser==$realuser && $cpass==$realpass) { $_SESSION["auth_username"] = $user; $_SESSION["userplusip"] = $userplusip; } ?> PHP: how can i fix the errors? thanks in advance.
well for starters you have it set so it looks for a to go to after logged in named after the user. Try to make a page like members.php and send it there!
as you can see, i have JavaScript in the beginning thats suppose to forward to main.php whether tho logins correct or not. the idea is that main.php will make sure there is a session and all that stuff. Im getting errors on the validate script then main.php wont recognize the session. Heres main.php <?php session_start(); //gets ip address $ip = $_SERVER['REMOTE_ADDR']; //checks for active session if(isset($_SESSION["auth_username"])&&isset($_SESSION["userplusip"])) { $user = $_SESSION["auth_username"]; $userplusip = $user . $ip; if ($userplusip==$_SESSION["userplusip"]) { $file = "users/" . $user . ".php"; include($file); } else { header ( 'Location: index.htm' ); exit; } } else { header ( 'Location: index.htm' ); exit; } ?> PHP:
The way you are doing it is not simple at all, what I suggest is to not use any javascript or anything like that and just a simple meta refresh where it will redirect the member to main.php. Using javascript when it comes to logins and sessions gets really tricky. This way should resolve all problems you are having.
the problem is that your PHP code is always going to execute before your JavaScript onload code. So the script is trying to include a different page before your JavaScript gets to execute. The problem is this line: include($user . ".php"); PHP: This bdougan.php page doesn't exist, and it's trying to include it in this page, which is only going to redirect to main.php after 5 seconds anyway. Why not just remove that "include" line completely, or just redirect the whole page to main.php to begin with, like this: header("location: main.php"); exit(0); PHP:
Why even use Javascript? If it is a script you got from the internet, I advise you use this instead: http://awesomephp.com/?Membership Peace,