473,396 Members | 2,092 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

do not understand Cannot send session cookie - headers already sent

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
11 2974
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
6,050 Expert 4TB
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
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
4,258 Expert 4TB
Are you sure that there is no blank following the <?php. If so take it out.

Ronald
Feb 25 '08 #5
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
4,258 Expert 4TB
Something must have been outputted before the session_start() was executed. You sure that was all the code?

Ronald
Feb 27 '08 #7
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
1,654 Expert 1GB
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
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
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
1,654 Expert 1GB
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

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

Similar topics

2
by: mr_burns | last post by:
Hi, i am getting the following errors when running my php script: Warning: Cannot send session cookie - headers already sent by (output started at ...
4
by: Bob | last post by:
Seem to have a problem ending a session. I get the following message. Warning: session_start(): Cannot send session cookie - headers already sent by (output started at...
19
by: lawrence k | last post by:
How can I find out where my script is outputting to the screen for the first time? My error logs are full of stuff like this: PHP Warning: session_start(): Cannot send session cache...
1
by: juergen | last post by:
Hi, there are many postings on this subject, I have read them put don't have an answer. I get these warnings: Cannot send session cookie - headers already sent in, but my php-scripts are okay. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.