ttmt Posted February 17, 2009 Share Posted February 17, 2009 Hi all I have a simple login system were the correct username password will direct the user to a secure page using a session and headers. <?php require_once("includes/session.php"); require_once("includes/connection.php"); require_once("includes/functions.php"); ?> <?php if(isset($_POST['submit'])){ $errors = array(); $required_fields = array('username', 'password'); foreach($required_fields as $fieldname){ if(!isset($_POST[$fieldname]) || empty($_POST[$fieldname])){ $errors[] = $fieldname; } } $username = mysql_prep($_POST['username']); $password = mysql_prep($_POST['password']); if(empty($errors)){ $query = "SELECT user_id, username FROM users WHERE username = '{$username}' AND hash_password = '{$password}'"; $result = mysql_query($query); confirm_query($result); if(mysql_num_rows($result) == 1){ $found_user = mysql_fetch_array($result); $_SESSION['user_id'] = $found_user['user_id']; $_SESSION['username'] = $found_user['username']; echo "beforeHeader"."<br/>"; header('Location: imgSelect.php'); echo "afterHeader"; } } }else{ if(isset($_GET['logout']) && $_GET['logout'] == 1){ $message = "You are now logged out"; } $username = ""; $password = ""; } ?> The problem is the page doesn't redirect and just stays on the login page. I don't get any error message so I can't work out whats going on. I had this working on an old system but I've just updated to OSX 10.5, I'm using MAMP with PHP 5.1.6. Are there any settings I can change to show any errors Link to comment https://forums.phpfreaks.com/topic/145546-headers-not-working-no-errors-showing/ Share on other sites More sharing options...
Mchl Posted February 17, 2009 Share Posted February 17, 2009 You can not echo anything before header() Link to comment https://forums.phpfreaks.com/topic/145546-headers-not-working-no-errors-showing/#findComment-764100 Share on other sites More sharing options...
phpretard Posted February 17, 2009 Share Posted February 17, 2009 Make sure nothing is being echo-ed or printed on these pages: require_once("includes/session.php"); require_once("includes/connection.php"); require_once("includes/functions.php"); ------------------------------------------------------------ The problem in the code presented is: echo "beforeHeader"."<br/>"; // NO HTML BEFORE THE HEADER REDIRECT header('Location: imgSelect.php'); Link to comment https://forums.phpfreaks.com/topic/145546-headers-not-working-no-errors-showing/#findComment-764103 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.