By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,303 Members | 1,245 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,303 IT Pros & Developers. It's quick & easy.

do not understand Cannot send session cookie - headers already sent

P: 8
i have changed my login .php file to the following

this file is opened directly and is not called from any other file
[PHP]<?php

// dBase file
$host=""; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name
$tbl_name=""; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
session_start();

if ($_GET["op"] == "login")
{
if (!$_POST["username"] || !$_POST["password"])
{
die("You need to provide a username and password.");
}

// Create query
$q = "SELECT * FROM `dbUsers` "
."WHERE `username`='".$_POST["username"]."' "
."AND `password`=PASSWORD('".$_POST["password"]."') "
."LIMIT 1";
// Run query
$r = mysql_query($q);

if ( $obj = @mysql_fetch_object($r) )
{
// Login good, create session variables
$_SESSION["valid_id"] = $obj->id;
$_SESSION["valid_user"] = $_POST["username"];
$_SESSION["valid_time"] = time();

// Redirect to member page
Header("Location: members.php");
}
else
{
// Login not successful
die("Sorry, could not log you in. Wrong login information.");
}
}
else
{
//If all went right the Web form appears and users can log in
echo "<form action=\"?op=login\" method=\"POST\">";
echo "Username: <input name=\"username\" size=\"15\"><br />";
echo "Password: <input type=\"password\" name=\"password\" size=\"8\"><br />";
echo "<input type=\"submit\" value=\"Login\">";
echo "</form>";
}
?>[/PHP]

this is the screen i am getting when i acces the page


Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at D:\virtualservers\182763\root\test\login\lo\login. php:1) in D:\virtualservers\182763\root\test\login\lo\login. php on line 12

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at D:\virtualservers\182763\root\test\login\lo\login. php:1) in D:\virtualservers\182763\root\test\login\lo\login. php on line 12


i would like some help please in locateing the sourtce of the errors

i know the errors are from the <?php in line one but therfe are NO spaces after this line only a return

i get the error when i enter a correct or a false user name

i know the database info i put in is correct as i can add data to the table fine

thanks
Feb 25 '08 #1
Share this Question
Share on Google+
11 Replies


P: 8
i was also wondering if it could be a setup fault on my server as i have been reciveing the same sort of errors useing differant code

all i am trying to do is create a database login
Feb 25 '08 #2

Markus
Expert 5K+
P: 6,050
session_start() needs to be at the very top of your page! ALL THE TIME!
[php]
<?php
session_start();

// rest of code

[/php]
Feb 25 '08 #3

P: 8
i have put the session start in as you suggested and this is now the error i am reciveng


Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at D:\virtualservers\182763\root\test\login\lo\login. php:1) in D:\virtualservers\182763\root\test\login\lo\login. php on line 2

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at D:\virtualservers\182763\root\test\login\lo\login. php:1) in D:\virtualservers\182763\root\test\login\lo\login. php on line 2
Feb 25 '08 #4

ronverdonk
Expert 2.5K+
P: 4,258
Are you sure that there is no blank following the <?php. If so take it out.

Ronald
Feb 25 '08 #5

P: 8
there is deffinetly no blanks after or before the <?php command

could it be somethingto do with the setup on my server as i have been getting similar problems with lots of different types of script i have been trying?

all i want is a simple login process
Feb 27 '08 #6

ronverdonk
Expert 2.5K+
P: 4,258
Something must have been outputted before the session_start() was executed. You sure that was all the code?

Ronald
Feb 27 '08 #7

P: 8
Something must have been outputted before the session_start() was executed. You sure that was all the code?

Ronald
there is no other code


that is why i think it might be on my server that is the problem

the file is located at http://equifor.soon2b.net/test/login/lo/login.php

please can you try and run it and see if you are getting the same errors i am

it is really frustrateing me

thanks
Feb 28 '08 #8

hsriat
Expert 100+
P: 1,654
there is deffinetly no blanks after or before the <?php command

could it be somethingto do with the setup on my server as i have been getting similar problems with lots of different types of script i have been trying?

all i want is a simple login process
No line break too?

This error is only shown if you have sent something before the header is set.
Feb 29 '08 #9

P: 8
there is nothing else in the file apart from what is shown

as i have said i have had similar problems with various files all with the same responce
Feb 29 '08 #10

P: 1
Same thing is happening to me and it has me tearing my hair out.

I have downloaded and customised a script that allows users to enter a password in order to move to a part of the site I want protected from the general public.

I debugged the script and had it working on my development machine (fedora 7, apache and php 5.x). I thought i was doing great, and then I uploaded it to the production machine which is Windows 2k3, IIS 6 and Php 5.x. That's when the wheels came off and i start getting this error.

What is going on? I always seem to add extra to my development time by having to work around the Windows insanity.
Mar 29 '08 #11

hsriat
Expert 100+
P: 1,654
Same thing is happening to me and it has me tearing my hair out.

I have downloaded and customised a script that allows users to enter a password in order to move to a part of the site I want protected from the general public.

I debugged the script and had it working on my development machine (fedora 7, apache and php 5.x). I thought i was doing great, and then I uploaded it to the production machine which is Windows 2k3, IIS 6 and Php 5.x. That's when the wheels came off and i start getting this error.

What is going on? I always seem to add extra to my development time by having to work around the Windows insanity.
If you are using Notepad, then open the file in another editor and remove the stuff before sending header.

Regards
Mar 29 '08 #12

Post your reply

Sign in to post your reply or Sign up for a free account.