Jump to content

[SOLVED] headers cannot be sent problem


dennismonsewicz

Recommended Posts

When i have this script in place

 

// Begin session
if (!isset($_SESSION)) {
session_start();
}

require_once('config/connection.php'); 
// Check email and password exist
if(isset($_REQUEST['login_submit'])) {
$user = trim($_REQUEST['email']);
$pass = trim($_REQUEST['password']);
$query_users = "SELECT * FROM members WHERE mem_email = '$user' AND mem_pass = '$pass'";
$rs_users = mysql_query($query_users);
$row_users = mysql_fetch_assoc($rs_users);
$personExists = mysql_num_rows($rs_users);
if($personExists) {
	$_SESSION['authenticated'] = $row_users['user_id'];
	header("location: user/");
} else {
	header("location: login.php?notification=badlogin");
}
}

 

I get the cannot modify header info PHP error message... if I can't use the header(); function then what is a better practice? no HTML is being sent before this is processed... so i don't know whats wrong

Link to comment
https://forums.phpfreaks.com/topic/144289-solved-headers-cannot-be-sent-problem/
Share on other sites

Check for a whitespace between the top of the file and the <?php  any type of character (even whitespace) send to the browser will cause this error.

 

Here is an example:


<?php

 

The above is bad, it should be:

 

<?php

 

However, you should get this with the session_start, but I get the feeling it is never being initiated with how you attempt to start it. Start the session no matter if $_SESSION is there, your check is not really doing any good.

 

EDIT:

Added more.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.