Jump to content

Recommended Posts

this is the error I'm getting.

Warning: Cannot modify header information - headers already sent by (output started at index.php:11) in functions.php on line 30

 

what I am trying to do is get the header to work in the functions.php file, functions.php is included at the very top of the page, I'm not sure why I'm getting this as an issue...

 

Any help much appreciated, thanks

Link to comment
https://forums.phpfreaks.com/topic/181806-solved-header-confusion/
Share on other sites

Read the error:

output started at index.php:11 (line 11)

 

You would need to determine what index.php is doing on (or up to) line 11 that is producing output and either eliminate it (assuming it is unintentional) or rearrange your logic (assuming the output is intentional) so that the output occurs after the header() statement or the header() statement is before the code sending the output.

Here's my code...

<?php  require_once('functions.php');

if(isset($_POST['login'])){

login_user($_POST['login_email'], $_POST['login_pass']);

} 

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Login</title>
</head>

<body>
<div id="login_error">
</div>
<form id="login" method="post" action="<?php $_SERVER['PHP_SELF'];  ?>">
<label>E-mail:
<input type="text" name="login_email" id="login_email" />
</label>
<label>Password:
<input type="password" name="login_pass" id="login_pass" />
</label>
<input type="submit" name="login" value="login"  id="Login" />
</form>
</body>
</html> 

 function login_user($email, $password){

$username = secure_var($email);
$password = md5($password);

if ($username != NULL and $password != NULL){

	$login_query = mysql_query("SELECT * FROM user_info WHERE email = '$email' AND password = '$password'");

	$login_status = mysql_num_rows($login_query);
	$login_vars = mysql_fetch_array($login_query);


	if($login_status == 1){

	set_login_sessions($login_vars['email'], $password, $login_vars['auth']);
	header('Location: usercp.php');
	exit;

}

else { echo "The entered username and/or password are incorrect. Please try again."; }

}

else { echo "Please enter a username and/or password."; }


}
[/code

Your index.php file either has a bunch of crap before the <?php tag or your functions.php file is outputting something. If you put the opening <?php tag in index.php on a line by itself (move the require_once() statement down so it is on the line after the <?php tag) you can tell if the output is something in index.php or functions.php

 

 

The error doesn't seam to match your code,

can you post the full functions.php and index.php

 

also in your login_user function shouldn't

email = '$email'

  be

email = '$username' 

in the following

	$username = secure_var($email);
$password = md5($password);
if ($username != NULL and $password != NULL){
	$login_query = mysql_query("SELECT * FROM user_info WHERE email = '$email' AND password = '$password'");

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.