Jump to content

[SOLVED] problem with php headers


gli

Recommended Posts

logincheck.php file which process the login.php login form

<?php
require_once("session.php"); ?>
<?php require_once("functions.php"); ?>
<?php require_once("databasec.php"); ?>

<?php
$username = $_POST['username'];
$password = $_POST['password'];
$hashedpassword = sha1($password);

$query = "SELECT *";
$query .= "FROM users ";
$query .= "WHERE username = '{$username}' ";
$query .= "AND hashedpassword = '{$hashedpassword}' ";
$query .= "LIMIT 1";
$result_set = mysql_query($query);
confirm_query($result_set);
if (mysql_num_rows($result_set) == 1) {
$found_user = mysql_fetch_array($result_set);

$_SESSION['user_id'] = $found_user['id'];
$_SESSION['username'] = $found_user['username'];

redirect_to("login.php");

} else {
$message = "Username/password incorrect. <br />
Please make sure your caps lock key is off and try again.";
echo $message;
}
?>

 

functions.php file

<?php	



function confirm_query($result_set) {
	if (!$result_set) {
		die("Database query failed: " . mysql_error());
	}
}

	function redirect_to( $location = NULL ) {
	if ($location != NULL) {
		header("Location: {$location}");
		exit;
	}
}
?>

 

 

When im trying to login it shows:

Warning: Cannot modify header information - headers already sent by (output started at /home/www/jimperija.atwebpages.com/functions.php:19) in /home/www/jimperija.atwebpages.com/functions.php on line 13

 

where is the problem?

Link to comment
Share on other sites

The problem is that you are sending white space to the browser. Anything that is outside of PHP tags will be sent to the browser as plain text. Try:

 

<?php
require_once("session.php");
require_once("functions.php");
require_once("databasec.php");


$username = $_POST['username'];
$password = $_POST['password'];
$hashedpassword = sha1($password);

$query = "SELECT *";
$query .= "FROM users ";
$query .= "WHERE username = '{$username}' ";
$query .= "AND hashedpassword = '{$hashedpassword}' ";
$query .= "LIMIT 1";
$result_set = mysql_query($query);
confirm_query($result_set);
if (mysql_num_rows($result_set) == 1) {
$found_user = mysql_fetch_array($result_set);

$_SESSION['user_id'] = $found_user['id'];
$_SESSION['username'] = $found_user['username'];

redirect_to("login.php");

} else {
$message = "Username/password incorrect. <br />
Please make sure your caps lock key is off and try again.";
echo $message;
}
?>

Link to comment
Share on other sites

and...

Warning: Cannot modify header information - headers already sent by (output started at /home/www/jimperija.atwebpages.com/functions.php:19) in /home/www/jimperija.atwebpages.com/functions.php on line 13

 

again...

 

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.