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

new at sessions

Hello, I am using PHP 4.3.1 with register_globals off.

I want to pass information from one page to another and want to start a
session for this using: session_start() at the beginning of my page
searchresult.php

However, I get the following error:

Warning: session_start() [function.session-start]: Cannot send session
cookie - headers already sent by (output started at
/srv/www/htdocs/searchresult.php:7) in /srv/www/htdocs/searchresult.php
on line 8

Warning: session_start() [function.session-start]: Cannot send session
cache limiter - headers already sent (output started at
/srv/www/htdocs/searchresult.php:7) in /srv/www/htdocs/searchresult.php
on line 8

A session_ID is created but any $_SESSION['variable'] I define is not
recognised. What am I doing wrong??

Thanks in advance,
Edward

Jul 17 '05 #1
3 2830

"edward hage" <ed**@xs4all.nl> wrote in message
news:3f*********************@news.xs4all.nl...
Hello, I am using PHP 4.3.1 with register_globals off.

I want to pass information from one page to another and want to start a
session for this using: session_start() at the beginning of my page
searchresult.php

However, I get the following error:

Warning: session_start() [function.session-start]: Cannot send session
cookie - headers already sent by (output started at
/srv/www/htdocs/searchresult.php:7) in /srv/www/htdocs/searchresult.php
on line 8

Warning: session_start() [function.session-start]: Cannot send session
cache limiter - headers already sent (output started at
/srv/www/htdocs/searchresult.php:7) in /srv/www/htdocs/searchresult.php
on line 8

A session_ID is created but any $_SESSION['variable'] I define is not
recognised. What am I doing wrong??

Thanks in advance,
Edward


you have to call ob_start() before any other output, including spaces. so
put it right at the top of the page, and it should work ok.
Leslie
Jul 17 '05 #2
Leslie Hoare wrote:
"edward hage" <ed**@xs4all.nl> wrote in message
news:3f*********************@news.xs4all.nl...
Hello, I am using PHP 4.3.1 with register_globals off.

I want to pass information from one page to another and want to start a
session for this using: session_start() at the beginning of my page
searchresult.php

However, I get the following error:

Warning: session_start() [function.session-start]: Cannot send session
cookie - headers already sent by (output started at
/srv/www/htdocs/searchresult.php:7) in /srv/www/htdocs/searchresult.php
on line 8

Warning: session_start() [function.session-start]: Cannot send session
cache limiter - headers already sent (output started at
/srv/www/htdocs/searchresult.php:7) in /srv/www/htdocs/searchresult.php
on line 8

A session_ID is created but any $_SESSION['variable'] I define is not
recognised. What am I doing wrong??

Thanks in advance,
Edward

you have to call ob_start() before any other output, including spaces. so
put it right at the top of the page, and it should work ok.
Leslie

I tried ob_start(); before session_start(); but that did not help.

I also don't see why the connection between buffering output and a
session. Could anyone explain more about that?

Greetings, Edward

Jul 17 '05 #3
edward hage wrote:

Leslie Hoare wrote:
"edward hage" <ed**@xs4all.nl> wrote in message
news:3f*********************@news.xs4all.nl...
Hello, I am using PHP 4.3.1 with register_globals off.

I want to pass information from one page to another and want to start a
session for this using: session_start() at the beginning of my page
searchresult.php

However, I get the following error:

Warning: session_start() [function.session-start]: Cannot send session
cookie - headers already sent by (output started at
/srv/www/htdocs/searchresult.php:7) in /srv/www/htdocs/searchresult.php
on line 8

Warning: session_start() [function.session-start]: Cannot send session
cache limiter - headers already sent (output started at
/srv/www/htdocs/searchresult.php:7) in /srv/www/htdocs/searchresult.php
on line 8

A session_ID is created but any $_SESSION['variable'] I define is not
recognised. What am I doing wrong??

Thanks in advance,
Edward

you have to call ob_start() before any other output, including spaces. so
put it right at the top of the page, and it should work ok.
Leslie

I tried ob_start(); before session_start(); but that did not help.

I also don't see why the connection between buffering output and a
session. Could anyone explain more about that?


session_start() sends a cookie to the user's browser. Cookies must be sent in
the header. You cannot send headers once you start to send content, even a
single space or linebreak. The solution, then, is to put session_start() at the
top of your file, if possible.

This works:
-------------- START OF FILE ------------------
<?PHP
session_start();
?>
-------------- END OF FILE ------------------

This doesn't work because it outputs a blank line before the cookie is sent:
-------------- START OF FILE ------------------

<?PHP
session_start();
?>
-------------- END OF FILE ------------------
You don't need ob_start() to use sessions. It can be helpful, though, if you
need to output text before you call session_start(). It sticks the text in a
buffer, effectively delaying sending it until after session_start() sends the
cookie.

This works because it delays sending outputted text until after the cookie is
sent:
-------------- START OF FILE ------------------
<?PHP
ob_start();
?>

Hello World.

<?PHP
session_start();
ob_flush();
?>
-------------- END OF FILE ------------------

Regards,
Shawn

--
Shawn Wilson
sh***@glassgiant.com
http://www.glassgiant.com
Jul 17 '05 #4

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

Similar topics

2
by: The Plankmeister | last post by:
Hi... I'm trying my hardest to understand fully how sessions work and how best to use them. However, all I can find is information that doesn't tell me anything other than that sessions store...
13
by: jing_li | last post by:
Hi, you all, I am a newbee for php and I need your help. One of my coworker and I are both developing a webpage for our project using php. We have a copy of the same files in different location...
3
by: Maxime Ducharme | last post by:
Hi group We have a problem with sessions in one of our sites. Sessions are used to store login info & some other infos (no objects are stored in sessions). We are using Windows 2000 Server...
3
by: Will Woodhull | last post by:
Hi, I'm new here-- I've been reading the group for a couple of days. Nice group; I like the way n00b33 questions are handled. I've been using a Javascript routine in index.html to determine a...
2
by: Steve Franks | last post by:
According to the docs you tell ASP.NET to use cookieless sessions by setting a value in the config.web file. However, what if I wanted to determine at run time whether or not I wanted to use...
12
by: D. Shane Fowlkes | last post by:
This is a repost (pasted below). Since my original post, I've double checked the system clock and set all IIS Session Timeout values to 10 minutes. Still ...the problem occurs. I've also...
6
by: Daniel Walzenbach | last post by:
Hi, I have a web application which sometimes throws an “out of memory” exception. To get an idea what happens I traced some values using performance monitor and got the following values (for...
22
by: magic_hat60622 | last post by:
Hi all. I've got an app that dumps a user id into a session after successful login. the login page is http://www.mydomain.com/login.php. If the user visits pages on my site without the www (i.e.,...
13
Frinavale
by: Frinavale | last post by:
One of the most fundamental topics in web design is understanding how to pass information collected on one web page to another web page. There are many different ways you could do this: Cookies,...
3
Atli
by: Atli | last post by:
Introduction: Sessions are one of the simplest and more powerful tools in a web developers arsenal. This tool is invaluable in dynamic web page development and it is one of those things every...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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.