aaronrb Posted October 12, 2007 Share Posted October 12, 2007 Hi guys, been working on a login scipt, have used some ideas i seen in tutorials, login n that works but doesnt redirect properly. code is here http://pastebin.com/m77322686 any helpwill be great, thanks in advance a Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted October 12, 2007 Share Posted October 12, 2007 try double quoting it? Quote Link to comment Share on other sites More sharing options...
aaronrb Posted October 12, 2007 Author Share Posted October 12, 2007 thanks for the speedy rsponse, but no luck ! Quote Link to comment Share on other sites More sharing options...
aaronrb Posted October 14, 2007 Author Share Posted October 14, 2007 anybody else able to help? Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted October 14, 2007 Share Posted October 14, 2007 Post more info about the script. Such as what is it supposed to do, whats happens when you run the script etc. Don't just dump the code on us. Quote Link to comment Share on other sites More sharing options...
aaronrb Posted October 14, 2007 Author Share Posted October 14, 2007 ok sorry. it is suppossed to check if a user is logged in, if they arent it shows them the login page, then once sucessfully logged in it creates a cookie, and redirects to the originally requiested page. Quote Link to comment Share on other sites More sharing options...
kratsg Posted October 14, 2007 Share Posted October 14, 2007 Changed: if($_COOKIE['user'] == " ") //to if(!isset($_COOKIE['user'])) I also changed all header functions to be double quoted, so you don need to concatenate (less characters and simpler). Change each line mentioned above the code, to what the code shows. Lines 12-20: if(isset($_COOKIE['user'])) { // if there is a cookie redirect to required page header('Location: http://admin.fsma.co.uk/login2.php'); echo "cookie set"; exit; } Line 22: if(!isset($_COOKIE['user']) && $_GET['action'] == "Login")//if no cookie and action is login Line 42: header("Location: http://$refer"); Line 51: header("Location: http://admin.fsma.co.uk/login2.php?refer=$refer"); Quote Link to comment Share on other sites More sharing options...
aaronrb Posted October 14, 2007 Author Share Posted October 14, 2007 hi cheers for that but all code changed as mentioned, and still get the same error. new code posted here http://pastebin.com/m62661a5b i dont understand, i have checked everything that i can think would cause an error. and no luck ! Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted October 14, 2007 Share Posted October 14, 2007 Changed your code: <?php // if there is a cookie redirect to required page if(isset($_COOKIE['user']) && !empty($_COOKIE['user'])) { header('Location: http://admin.fsma.co.uk/login2.php'); echo "cookie set"; exit; } // login elseif(isset($_GET['action']) && $_GET['action'] == "Login") { // check if username field is field in. If it doesn't set an error message if(!isset($_POST['Username']) || empty($_POST['Username'])) { $error[] = 'Please provide a username'; } // check if passwoord field is field in if(!isset($_POST['Password']) || empty($_POST['Password'])) { $error[] = 'Please provide a password'; } // check to see if there is any validation errors from above. If there is display the errors. if(isset($error) && is_array($error)) { echo "Please correct the following errors:\n<ul>\n<li>" . implode("</li>\n<li>", $error) . "</li>\n</ul>"; include 'login.php'; exit; } // validation passed continue to login user with supplies details $user = mysql_real_escape_string($_POST['Username']); $password = md5($_POST['Password']); $refer = (isset($_POST['Refer']) && !empty($_POST['Refer'])) ? $_POST['Refer'] : 'index.php'; require 'db_connect.php'; $query = "SELECT * FROM users WHERE user='$user' AND `password`='$password'"; $result = mysql_query($query) or die("Error" . mysql_error()); if(mysql_num_rows($result) == 1) { //if login successful. set cookie & go to referrer. setcookie('user', $user); /* Expires when browser closes */ header('Location: http://' . $refer); exit; } else { // Not authenticated header('Location: http://admin.fsma.co.uk/login2.php?refer='.$refer); exit; } } // no cookie or action found else { echo 'cookie or action not found!'; } ?> Quote Link to comment Share on other sites More sharing options...
aaronrb Posted October 14, 2007 Author Share Posted October 14, 2007 that code looks alot neater but still not redirecting properly just to clarify what should i be putting at the top of each page that requires a login? Quote Link to comment Share on other sites More sharing options...
aaronrb Posted October 17, 2007 Author Share Posted October 17, 2007 hey all, i have been trying to find a possible solution but there is still no answer. Regards Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.