Jump to content

headers not working - NO errors showing


ttmt

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.