473,398 Members | 2,165 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,398 software developers and data experts.

can I still send cookies after I've called session_start()

I was trying to set a cookie before I called session_start() and it was
giving me an error. But isn't sessions really just a cookie? Why would
it matter if I sent a cookie before session_start? Can I set them
afterwards?

Jul 21 '05 #1
8 2220
You *can* set a cookie without calling session_start(). Do you mean a
session variable? You can't do this without calling session_start():
$_SESSION['sessionvar'] = 'value';
But you can do this:
setcookie('cookiename', 'value', time()+36000);
and then read the cookie like this:
$_COOKIE['cookiename'];

http://www.w3schools.com/php/php_cookies.asp

Jul 21 '05 #2
>You *can* set a cookie without calling session_start(). Do you mean a
session variable? You can't do this without calling session_start():
$_SESSION['sessionvar'] = 'value';


No, I meant, I was setting a cookie, then calling session_start(), and
I was getting an error. Can I call session_start() and then set a
cookie? I want to set a permanent cookie that will last one million
seconds. I also want sessions.

Jul 21 '05 #3
On 21 Jul 2005 08:29:01 -0700, lk******@geocities.com wrote:
I was trying to set a cookie before I called session_start() and it was
giving me an error.
Your post is missing a vital piece of information.
But isn't sessions really just a cookie? Why would
it matter if I sent a cookie before session_start?
It doesn't.
Can I set them afterwards?


Yes, and before.

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 21 '05 #4
JDS
On Thu, 21 Jul 2005 11:43:55 -0700, lkrubner wrote:
No, I meant, I was setting a cookie, then calling session_start(), and
I was getting an error. Can I call session_start() and then set a
cookie? I want to set a permanent cookie that will last one million
seconds. I also want sessions.


AND WHAT IS THE ERROR????

sheesh

--
JDS | je*****@example.invalid
| http://www.newtnotes.com
DJMBS | http://newtnotes.com/doctor-jeff-master-brainsurgeon/

Jul 22 '05 #5
On Thu, 21 Jul 2005 11:43:55 -0700, lkrubner wrote:
No, I meant, I was setting a cookie, then calling session_start(), and
I was getting an error. Can I call session_start() and then set a
cookie? I want to set a permanent cookie that will last one million
seconds. I also want sessions.


AND WHAT IS THE ERROR????


This is the error I'm getting:

<b>Warning</b>: session_start(): Cannot send session cookie - headers
already sent in
<b>/home/httpd/vhosts/publicdomainsoftware.org/httpdocs/pdsIncludes/CommandStartSession.php</b>
on line <b>14</b><br />
<br />
<b>Warning</b>: session_start(): Cannot send session cache limiter -
headers already sent in
<b>/home/httpd/vhosts/publicdomainsoftware.org/httpdocs/pdsIncludes/CommandStartSession.php</b>
on line <b>14</b><br />
This is line 14 and 15 of CommandStartSession:

session_start();
session_register();
I used my text editor (RedCrimson) and did a search of all the files in
this project, looking for session_start(). I thought maybe, by
accident, I was calling it twice. But no, it only appears once.

Oddly, when I call session_start(), output buffering is on, so I'm not
sure how I get that error. Later I set a cookie, then I sent a charset
header indicating that the characters are UTF-8, then I end output
buffering.

I thought the output buffering would keep me safe from this kind of
error, but apparently not.

Aug 5 '05 #6
>On Thu, 21 Jul 2005 11:43:55 -0700, lkrubner wrote:
No, I meant, I was setting a cookie, then calling session_start(), and
I was getting an error. Can I call session_start() and then set a
cookie? I want to set a permanent cookie that will last one million
seconds. I also want sessions.


AND WHAT IS THE ERROR????


You can see the problem here:

http://www.publicdomainsoftware.org/

Aug 5 '05 #7
lk******@geocities.com wrote:
On Thu, 21 Jul 2005 11:43:55 -0700, lkrubner wrote:
No, I meant, I was setting a cookie, then calling session_start(), and
I was getting an error. Can I call session_start() and then set a
cookie? I want to set a permanent cookie that will last one million
seconds. I also want sessions.


AND WHAT IS THE ERROR????

You can see the problem here:

http://www.publicdomainsoftware.org/


<br />
<b>Warning</b>: session_start(): Cannot send session cookie - headers already
sent in

You're sending <br /> before the session_start call.

You can't send ANYTHING (including a blank line) before the session_start() call.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Aug 6 '05 #8
On Fri, 05 Aug 2005 21:42:15 -0500, Jerry Stuckle <js*******@attglobal.net>
wrote:
lk******@geocities.com wrote:
On Thu, 21 Jul 2005 11:43:55 -0700, lkrubner wrote:

No, I meant, I was setting a cookie, then calling session_start(), and
I was getting an error. Can I call session_start() and then set a
cookie? I want to set a permanent cookie that will last one million
seconds. I also want sessions.

AND WHAT IS THE ERROR????

You can see the problem here:

http://www.publicdomainsoftware.org/


<br />
<b>Warning</b>: session_start(): Cannot send session cookie - headers already
sent in

You're sending <br /> before the session_start call.


That's part of the PHP error message:

andyh@server:/usr/src/php-5.0.4/main$ nl -ba main.c | grep -2 '<br />'
736 char *append_string =
INI_STR("error_append_string");
737 char *error_format = PG(html_errors) ?
738 "%s<br />\n<b>%s</b>: %s in
<b>%s</b> on line <b>%d</b><br />\n%s"
739 : "%s\n%s: %s in %s on line
%d\n%s";
740 php_printf(error_format,
STR_PRINT(prepend_string), error_type_str, buffer, error_filename,
error_lineno, STR_PRINT(append_string));

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Aug 6 '05 #9

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

Similar topics

1
by: windandwaves | last post by:
Hi Gurus I am basically sorry that I have to bother you about this. I am a PHP beginner and I have been studying sessions and cookies over the last few weeks. I have learned lots, but I am...
6
by: Mark | last post by:
Hi... I've come across some weird bug with Response.Cookies. Or maybe it will be called "by design" but for the life of me I can't figure out what purpose it would serve. If you're setting a...
3
by: lawrence k | last post by:
I'm getting this warning: PHP Warning: session_start(): Cannot send session cache limiter - headers already sent 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...
4
by: André | last post by:
Hi, I try to create and render a graphic among other objects like e.g. tables, labels, buttons. The tables are not a problem, neither the graphic. My problem is that i can't render both...
4
by: Gunnar G | last post by:
How can I send a lot of data from foo.php to bar.php ? This might happen if foo.php echo some text and bar.php returns an image that should be displayed below the text that was echo:ed, and...
4
by: three-eight-hotel | last post by:
I'm somewhat of a newbie to PHP coding, but have developed a site using the technology, and have been pleasantly surprised by the capabilities offered. I am more comfortable in the ASP world,...
1
by: pedalpete | last post by:
I'm building a facebook app, and have been following the guidelines and posting on the facebook message board, but can't seem to get anywhere. Facebook creates a session and cookie on the users...
11
by: craigtomo | last post by:
i have changed my login .php file to the following this file is opened directly and is not called from any other file <?php // dBase file $host=""; // Host name $username=""; // Mysql...
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: 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
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: 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
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
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.