Jump to content

session_start() error, can't figure it out.


DoorsRent

Recommended Posts

I've read through a ton of posts on this error, but am still needing help.

 

error:

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at F:\httpd-2.2-x64\htdocs\craig2\profile.php:1) in F:\httpd-2.2-x64\htdocs\craig2\auth.php on line 3

 

profile.php:

<?php
require_once("auth.php");

?>

..lots of html code...

<?PHP

print "test";


?>

...lots of html code...

 

 

auth.php:

<?PHP
//Authorizes access, or denies access based on login status
session_start();

if ($_SESSION['is_logged_in']) 
{
	//set variables
	$email = $_SESSION['email'];
	print "Session Valid";
} 
else 
{
	// display data for users who aren't logged in.
	//header("Location: login.html");
	print "Session not valid";

}


?>

 

There is no whitespace before or after any of the php tags (checked by turning on whitespace indicators in editor).  No html or anything else before the first php tag of the files.  The top of the file looks exactly like what I posted.

 

Thanks a lot!

Link to comment
https://forums.phpfreaks.com/topic/149588-session_start-error-cant-figure-it-out/
Share on other sites

After content/white-space, the second most common reason for "output started in yourfile" on line one is the BOM (Byte Order Mark) characters of a file that has been saved in UTF-8 encoding. Save your file as ANSI/ASCII.

You've allready started the session in your auth.php [session_start();]

 

Do you have a page where it includes the profile.php ?

 

I have a page that has this:

<?php
session_start();

...
header("Location: profile.php");
...
?>

 

That's how I get to pofile.php.  I think that may be the problem, but I don't know how to fix it.

 

Do you just call session_start() once for all your .php files?  If I comment out session_start() from auth.php I don't get the error, but I also can't pull up my session variables.

 

Save your file as ANSI/ASCII.

Ya, I checked that and it's ascii.

  • 2 weeks later...

output started at ...\profile.php:1
The only way you can get that error message is if there is something - content, newline, tab, space, or BOM before the <?php tag on that line. Check again.

 

Ok, I've been trying and trying to get this to work.  I simplified it into a new "logintester" program.  From everything I can do in my editor I believe there is no whitespace or anything before the <?php tags.  I have it set to ANSI.  I just can't figure this error out and I know it's got to be a simple error!

 

I'm going to attach my files here, I'd be very grateful if someone could look at them to see what I'm doing wrong.  Here's the code (also attached):

 

login.php

<?php session_start();

include('database_info.php');

$dbcnx = mysql_connect(host, username, password);
if (!$dbcnx){
	echo '<p>Error connecting to database</p>';
	exit();	
}

mysql_select_db(database_name) or die(mysql_error());	//choose database to work with	

// retrieve form data 
$email = mysql_real_escape_string($_POST['username']);	
$password = sha1(pass_salt.$_POST['password']);		

$query = "SELECT id 
		  FROM ". table_name.
		" WHERE email = '$email' AND password = '$password'
		  ORDER BY id";


$result = mysql_query($query) or die(mysql_error());
$num = mysql_num_rows($result);

if ($num>0)
{
	//username and password correct
	$_SESSION['is_logged_in'] = true;
	$_SESSION['email'] = $email;
	$_SESSION['id'] = mysql_result($result,0);
	header("Location: profile.php");
}
else
{	
	//user or pass incorrect
	echo "Wrong Info";
	exit;
}
?>

 

auth.php

<?php session_start();

if ($_SESSION['is_logged_in']) 
	$email = $_SESSION['email'];
else 
	echo "Can't login!";

?>

 

profile.php

<?php include('auth.php');
include('database_info.php');

echo "Logged in!";



?>

 

database_info.php

<?php

define('host','localhost');
define('username','root');
define('password','123456');	
define('database_name', 'users_data');
define('table_name', 'data');
define('pass_salt', 'Jv76Ht');		//concatenated to every password to complicate the password


?>

 

Thank you very much!

 

 

[attachment deleted by admin]

Well, profile.php (the file that the error message states where the output is occuring on line 1) in the zip attachment is in UTF-8 format.

 

Wow, thank you so much!  The program I was using wasn't set to UTF-8 (set to ANSI), but maybe I didn't get another setting correct.  I think profile.php was the only one not set to ANSI.

 

I downloaded Notepad++ to see if a different devel studio would work.  Now everything works just great!

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.