473,224 Members | 1,636 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,224 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 2212
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...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.