Jump to content

[SOLVED] session_start() problem


zamp0e

Recommended Posts

Hello, I have small problem with my session_start() it seems, here are the first 18 lines of code:

 

 

<?php

$host = "*******";

$user = "******";

$pass = "******";

$db = "******";

 

 

$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");

 

mysql_select_db($db) or die ("Unable to select database!");

 

$query = "SELECT * FROM ******";

$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());

 

session_start();

include("login.php");

 

?>

 

 

I get two errors when I open this file in the browser:

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\xampp\htdocs\test\index.php:1) in C:\xampp\htdocs\test\index.php on line 15

 

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\test\index.php:1) in C:\xampp\htdocs\test\index.php on line 15

 

Any help would be greatly appreciated :)

 

 

Link to comment
https://forums.phpfreaks.com/topic/160010-solved-session_start-problem/
Share on other sites

That won't help when the output is started on line 1 of the file.

 

You either have some characters before the <?php tag or your file has been saved in UTF-8 encoding and the BOM (Byte Order Mark) characters that the editor places at the start of the file are the output that is being sent to the browser.

 

Make sure there are no characters in the file before the <?php tag and make sure your files is saved in ANSI (ASCII) encoding or if you must save the file in UTF-8 encoding, save it without the BOM.

Hello and thanks for the fast reply, although I have already tried to set session_start() on the top, like this:

 

<?php

session_start();

?>

<?php

 

$host = "******";

$user = "******";

$pass = "******";

$db = "******";

 

 

And like this:

<?php

session_start();

$host = "******";

$user = "******";

$pass = "******";

$db = "******";

 

 

I'm still having the same warnings, although the line changes

 

 

you have to put the session_start() to the first line, just follow the <?php

 

then, if still doesn't work, create a new file and paste all the codes there, bcoz maybe here're space or something else infront of the <?php.

 

and the reason is that maybe you create the file by some software.

where do I control that ?

It's part of your editor's file save/save as dialog. If the editor you are using does not have any settings related to the format the file is being saved as, you need to use a programming editor such as notepad++ http://notepad-plus.sourceforge.net/uk/site.htm

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.