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

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.