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

ini_set() not working as expected

When running the following code I get a warning:

<?
ini_set('session.use_cookies',0);
?>
random text
<?
session_start();
?>

The output / warning I'm getting is this:

random text
Warning: session_start(): Cannot send session cache limiter - headers
already sent (output started at /path/to/file.php:5) in
/path/to/file.php on line 6

Shouldn't the fact that I'm setting session.use_cookies to 0, via
ini_set, prevent this error from taking place?

Jun 8 '06 #1
7 4343
yawnmoth wrote:
When running the following code I get a warning:

<?
ini_set('session.use_cookies',0);

random text
<?
session_start();


The output / warning I'm getting is this:

random text
Warning: session_start(): Cannot send session cache limiter - headers
already sent (output started at /path/to/file.php:5) in
/path/to/file.php on line 6

Shouldn't the fact that I'm setting session.use_cookies to 0, via
ini_set, prevent this error from taking place?


The headers are sent as soon as some output is sent. In your case you are
sending a blank followed by the text random text, before doing the
session_start().
Jun 8 '06 #2

Paul Lautman wrote:
yawnmoth wrote:
<snip>
The headers are sent as soon as some output is sent. In your case you are
sending a blank followed by the text random text, before doing the
session_start().

Why isn't the ini_set preventing that, though? I don't want PHP to
propogate PHPSESSID via $_COOKIE - I want it to propogate through
$_GET.

I could just do it via .htaccess or php.ini, but doing so would still
leave me wondering why ini_set doesn't work. As far as I know, it
should, yet it doesn't, and I'd like to know why.

Jun 8 '06 #3
"yawnmoth" <te*******@yahoo.com> wrote in message
news:11*********************@j55g2000cwa.googlegro ups.com...

Paul Lautman wrote:
yawnmoth wrote:
<snip>
The headers are sent as soon as some output is sent. In your case you are
sending a blank followed by the text random text, before doing the
session_start().

Why isn't the ini_set preventing that, though? I don't want PHP to
propogate PHPSESSID via $_COOKIE - I want it to propogate through
$_GET.

I could just do it via .htaccess or php.ini, but doing so would still
leave me wondering why ini_set doesn't work. As far as I know, it
should, yet it doesn't, and I'd like to know why.

Ini_set doesn't work that way because it's never meant to work that way in
the first place. It doesn't affect the way headers and body are sent. once
you start sending the body, session information cannot be sent, headers were
already sent. When you close the first php tag, the random text is echoed
out to client. That's when headers are sent and sending body begins.

After ini_set you might want to call ob_start() if you want the output to be
buffered. Then you should be able to set session variables later because
output doesn't begin until ob_flush() is called or page ends.

--
"ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" -lpk
sp**@outolempi.net | Gedoon-S @ IRCnet | rot13(xv***@bhgbyrzcv.arg)
Jun 8 '06 #4

Kimmo Laine wrote:
"yawnmoth" <te*******@yahoo.com> wrote in message
news:11*********************@j55g2000cwa.googlegro ups.com...
<snip>
Ini_set doesn't work that way because it's never meant to work that way in
the first place. It doesn't affect the way headers and body are sent. once
you start sending the body, session information cannot be sent, headers were
already sent. When you close the first php tag, the random text is echoed
out to client. That's when headers are sent and sending body begins.

After ini_set you might want to call ob_start() if you want the output to be
buffered. Then you should be able to set session variables later because
output doesn't begin until ob_flush() is called or page ends.


Here's another question, then. Why does it also not work when my
..htaccess has the following line added to it?:

php_flag session.use_cookies off

Does this mean that php_admin_flag has been set to on in an earlier
directory or am I doing something wrong?

Jun 8 '06 #5
Kimmo Laine wrote:
"yawnmoth" <te*******@yahoo.com> wrote in message
news:11*********************@j55g2000cwa.googlegro ups.com...

Paul Lautman wrote:
yawnmoth wrote:
<snip>
The headers are sent as soon as some output is sent. In your case
you are sending a blank followed by the text random text, before
doing the session_start().

Why isn't the ini_set preventing that, though? I don't want PHP to
propogate PHPSESSID via $_COOKIE - I want it to propogate through
$_GET.

I could just do it via .htaccess or php.ini, but doing so would still
leave me wondering why ini_set doesn't work. As far as I know, it
should, yet it doesn't, and I'd like to know why.

Ini_set doesn't work that way because it's never meant to work that
way in the first place. It doesn't affect the way headers and body
are sent. once you start sending the body, session information cannot
be sent, headers were already sent. When you close the first php tag,
the random text is echoed out to client. That's when headers are sent
and sending body begins.

But the manual does say: "If you are using cookie-based sessions, you must
call session_start() before anything is outputted to the browser."

Which implies that if you are not using cookie-based sessions, then you can
call session_start() after sending output to the browser.
Jun 8 '06 #6
Kimmo Laine wrote:
"yawnmoth" <te*******@yahoo.com> wrote in message
news:11*********************@j55g2000cwa.googlegro ups.com... <snip>It doesn't affect the way headers and body are sent. once
you start sending the body, session information cannot be sent, headers were
already sent. Rereading this... I'm not asking it to affect the way the headers and
the body are sent - I'm asking it to not send headers when sending the
session information. Headers are only necessary, after all, if cookies
are being set, and I don't want cookies to be set, at all.
When you close the first php tag, the random text is echoed
out to client. That's when headers are sent and sending body begins. I'm not disputing that.
After ini_set you might want to call ob_start() if you want the output to be
buffered. Then you should be able to set session variables later because
output doesn't begin until ob_flush() is called or page ends.

I don't want to buffer the output, though. I just don't want
session_start to use $_COOKIE.

In a similar vein, something that's always bugged me about PHP's
documentation regarding sessions is how it recommends you unset
$_SESSION vars before calling session_destory. As I understand it,
session_destory makes $_SESSION unavailable the next time the script is
called. During the current execution of it, however, the $_SESSION
vars still exist. unsetting the $_SESSION vars makes them unavailable
to the current execution of the script. But why does it matter? If
they don't need to be called after a certain point, how about just not
calling them? Unsetting can save memory, I suppose, but then why
aren't $_GET and $_POST unset after they've been assigned to variables
(if they are)?

All in all, php.net's documentation on sessions just strikes me as poor
compared to the rest of it.

Jun 9 '06 #7

yawnmoth wrote:
Kimmo Laine wrote:
"yawnmoth" <te*******@yahoo.com> wrote in message
news:11*********************@j55g2000cwa.googlegro ups.com...

<snip>
It doesn't affect the way headers and body are sent. once
you start sending the body, session information cannot be sent, headers were
already sent.

Rereading this... I'm not asking it to affect the way the headers and
the body are sent - I'm asking it to not send headers when sending the
session information. Headers are only necessary, after all, if cookies
are being set, and I don't want cookies to be set, at all.

Never mind. Set-Cookie isn't the only header session_start sends out,
apparently...

Jun 9 '06 #8

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

Similar topics

1
by: Oz | last post by:
This is long. Bear with me, as I will really go through all the convoluted stuff that shows there is a problem with streams (at least when used to redirect stdout). The basic idea is that my...
3
by: MBS | last post by:
I checked the official PHP documentation and it makes no mention of "@ini_set" function with the "@" symbol in front of it. The code I'm looking at does have the "at" symbol in front of...
2
by: TJ | last post by:
Hello All, We have a client who is providing Web Hosting Solutions. One of the features include PHP Scripting. For security reasons, we have disabled some PHP Functions including 'ini_set'....
6
by: howa | last post by:
ini_set( "short_open_tag", 1 ); phpinfo(); still showing 'off'
3
by: David | last post by:
I am puzzled, I want to change the upload_max_filesize setting, if I do this with ini_set('upload_max_filesize', 8000000); the upload_max_filesize is not set. However, if I make the change in...
24
by: Paul | last post by:
I am taking over an existing app and having trouble understanding their references. They have encapsulated Pear packages in the directory structure like: /site /site/html/Pear.php...
2
by: mrbog | last post by:
Here's my code: <?php error_reporting(E_ALL); ini_set("display_startup_errors","1"); ini_set("display_errors","1"); wefw wefwef=wefwe
1
by: henryrhenryr | last post by:
Hi Just wanted to find out which one is 'better': using ini_set() to change settings or using a function (eg below). By better I mean faster / more secure or balance of the two. The PHP manual...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.