473,372 Members | 1,549 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,372 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 4344
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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
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...

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.