473,396 Members | 2,109 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.

Warning: Cannot add header information - headers already sent

Hello,

I've recently started learning PHP and have a question.
I tried running below script which can be found at
http://se2.php.net/manual/sv/function.setcookie.php

but I keep getting this message on my browser, why?

Warning: Cannot add header information - headers already sent by
(output started at /var/www/cookietest.php:2) in
/var/www/cookietest.php on line 6

Warning: Cannot add header information - headers already sent by
(output started at /var/www/cookietest.php:2) in
/var/www/cookietest.php on line 7

Warning: Cannot add header information - headers already sent by
(output started at /var/www/cookietest.php:2) in
/var/www/cookietest.php on line 8

-----

<?
echo "Setting cookie";

$value = 'Test value';

setcookie("TestCookie", $value);
setcookie("TestCookie", $value, time()+3600); /* expire in 1 hour */
setcookie("TestCookie", $value, time()+3600, "/~rasmus/",
".example.com", 1);

echo "Cookie Set!";
?>
Jul 17 '05 #1
2 3144
Phyzlo a écrit le 08/03/2004 :
Hello, Hi
I've recently started learning PHP and have a question.
I tried running below script which can be found at
http://se2.php.net/manual/sv/function.setcookie.php

but I keep getting this message on my browser, why? Because you didn't read the doc about Cookies.
http://www.php.net/setcookie
You must NOT output anything before using setcookie()
You MUST reload the page to see the cookie set.
-----

<?
echo "Setting cookie"; Delete this line and it'll run.
$value = 'Test value';

setcookie("TestCookie", $value);
setcookie("TestCookie", $value, time()+3600); /* expire in 1 hour */
setcookie("TestCookie", $value, time()+3600, "/~rasmus/",
".example.com", 1);

echo "Cookie Set!";
?>

Jul 17 '05 #2
You're right thanks!

//Regards
Jedi121 <je*********@free.fr.Removethis> wrote in message news:<me********************************@free.fr.R emovethis>...
Phyzlo a écrit le 08/03/2004 :
Hello,

Hi
I've recently started learning PHP and have a question.
I tried running below script which can be found at
http://se2.php.net/manual/sv/function.setcookie.php

but I keep getting this message on my browser, why?

Because you didn't read the doc about Cookies.
http://www.php.net/setcookie
You must NOT output anything before using setcookie()
You MUST reload the page to see the cookie set.
-----

<?
echo "Setting cookie";

Delete this line and it'll run.

$value = 'Test value';

setcookie("TestCookie", $value);
setcookie("TestCookie", $value, time()+3600); /* expire in 1 hour */
setcookie("TestCookie", $value, time()+3600, "/~rasmus/",
".example.com", 1);

echo "Cookie Set!";
?>

Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: None | last post by:
Hello, I am a total newbie to PHP and programming in general. I am playing around with a PHP / MySQL shopping cart script which I found at...
3
by: Greg Scharlemann | last post by:
Does the redirect statement: header(Location:"http://www.newpage.com"); need to come before certain statements? I've setup a login page and try to redirect a user once they have logged in...
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...
5
by: nasse | last post by:
I am getting the following error msg whenever I try to login. I tried to turn my output_buffering = On in my php.ini but is not working for me. Would you please help me: Warning: Cannot modify...
8
by: mcserret | last post by:
I know this is a recurring problem that has been addressed here before, but even after reading all that has gone before, I am still stumped. I have a form that is designed to send data to a PHP...
2
by: smartic | last post by:
I'm having problem with header redirection that is my code: <?php header("location:Redirecting.php"); exit; ?> //Then the HTML It give me an error
3
by: mrosado | last post by:
Hi everybody, I have this problem.- The browser launch this two errors: Warning: session_start() : Cannot send session cache limiter - headers already sent (output started at...
3
by: gubbachchi | last post by:
Hi, I have written php code to retrive the image from mysql and display it on the webpage. Here is the code <?php require_once("DBConnect.php"); $gotten = @mysql_query("select user_photo from...
10
by: jessica87 | last post by:
hi there, i m using this coding to retrieve the file from database so that my user can download the file... <?php if (!isset($_GET)) die('Invalid Parameter'); include...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.