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

session data / header question?

201 100+
hello -

if session is started from the same page, and i have another script that needs to access header data with out destorying the session data.

a. should i store the header info in variables on the page then access them by the var in the page that needs them?

error desc:

currently if the session has started and that script is executed it resends the header info which appearantly destroys the session and errors "saying headers alread sent".

thanks in advance for your help.

theo e. werntz ii
Jan 15 '10 #1
9 2361
Atli
5,058 Expert 4TB
Hey.

I think you may be misunderstanding how headers and sessions work. Or I may be misunderstanding your post. Either way, this is how session do work.

A session has little to do with the actual headers. It only sends a session ID via a cookie (or in rare cases a GET parameter, but that is irrelevant here) - which is why it must be able to set a header. If you call session_start() again from within the same PHP page, or any PHP page included into that page, then it would have no effect.

If - after said page has been sent and the cookie has reached the client - the client does another request (via AJAX, for example) the session ID int the cookie will be sent to the server and the previously used session will be restored.

If you are getting a "headers already sent" warning and you session data is not being set, then odds are that your first call to session_start is failing. That error means that the headers can not be set because they have already been sent to the client, meaning the session cookie can not be sent.
Jan 15 '10 #2
wizardry
201 100+
thanks for the reply -

here are the errors:

cannot send session cookie - headers already sent by
cannot send session cache limiter - headers already sent by

i have an a script that is loaded from when it is first access.

i.e. www.domain.com -- loads then the script loads when its is threaded.

then the session server will start once the login form has been accessed on the same page.

i've tried adding that below the session marker but it gets the same error. meaning have the session loaded first on the page.

i know that session is working correctly, im able to access objects with that session data.

-- also not to get off topic do you have a good article on cookies?

thanks in advance for your help.
Jan 15 '10 #3
wizardry
201 100+
also the page that im having the problem is the index. the rest of the pages that i need that script on and they use sessions are working fine.

thanks, again in advance for your help!
Jan 15 '10 #4
Just make sure, you do not output anything before calling session_start().
Jan 16 '10 #5
wizardry
201 100+
nothing was outputed before the session start.

session start is at the begining of the page.

i.e.
Expand|Select|Wrap|Line Numbers
  1. if (!isset($_Session))
  2. {
  3. session_start();
  4. }
  5. ?>
  6. <!-- here is the script to be called after. -->
  7. <?php require_once('script.php'); ?>
  8.  
  9. -- html / and css -- not posting not needed for this debugging help.
  10.  
Ok as i posted earlier this way works on the rest of the site. excluding the INDEX.php

my question is why has it worked on all of the other pages but not the INDEX.php

i've tried moving the session_start module to the top or where the function needs it. but nothing. same issue. i've tried putting the script that needs to be ran before or after the session call to start. but same error.

Session do work. I use them and are able to output their variables on a echo "$_session";

thanks, again in advance for your help.

Theo Werntz II
Jan 16 '10 #6
Atli
5,058 Expert 4TB
Hey.

The session super-global is called $_SESSION, not $_Session or $_session, or any other variation thereof. It has to be all upper-case. (Variable names in PHP are case-sensitive.)

If you use the incorrect case PHP will just treat it as a typical variable, and create a normal array for you. It will work just fine on that page, but won't be stored between requests.
Jan 16 '10 #7
wizardry
201 100+
hey alti -

its not the variable case size. it is in case upper format.

could you re-read the previous post?

have you ran into any problems with index.php with using sessions?

sessions work through out the rest of the site? but not the index for this script. it works fine with out it but not with it added.


Thanks, in advance for your help!
Jan 16 '10 #8
Atli
5,058 Expert 4TB
@wizardry
I only mentioned that because your example code used a mixed-case version of it, which would be invalid.
In any case, if you are sure this is not the problem, I'm inclined to agree with nilayanand.

Can you post the entire beginning of the index.php, up to the point you call the session_start function?
The "headers already sent" error tells us there is something being sent to the browser before the function is called. We must find out what and remove it.

You can check out this article draft which Markus has been working on. It explains this problem in details.

@wizardry
It's Atli, by the way ;-)
(It seems most people want to put the L first. I don't know why xD)
Jan 17 '10 #9
wizardry
201 100+
thanks for the reply atli -

ok the code is their nothing else was copied besides where i was having the error.

i'm doing some more debugging.

thanks again for your help. will repost later currently working on this img loop array problem im having. can you look at the other post for me in forums php img loops?
Jan 17 '10 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Paul | last post by:
Hmmm, didn't seem to work. I have set session.use_cookies = 1 and session.use_trans_sid = 1 in my php.ini file. Index.php contains:...
6
by: John | last post by:
Hi. I am having a few header problems at the moment with a login page. I don't have my headers at the top of the page where I've learned I need to have them. However, I also know I'm supposed...
9
by: bajopalabra | last post by:
hi session("myVar") = rs.getRows( ) don't work when number of records is greater than 10 does anybody know WHY ??? is it a Session object limitation ??? thanks
4
by: raghavendra | last post by:
hi, i have gone through this link http://msdn.microsoft.com/library/default.asp?url=/workshop/security/privacy/customimportxml/thirdparty.asp.. i want to know, how to use this below code in...
4
by: DavidS | last post by:
First: There are several ways to confuse one regarding session timeout. (1) web.config - <sessionState timeout="20"> (2) IIS Manager | Internet Information Services | ServerNode | Default Web Site...
7
by: Doug | last post by:
An ASP.NET session cookie set on "www.mydomain.com" can not be accessed on "search.mydomain.com"; hence, a new session and cookie are being created on every sub-domain. This is occuring because...
9
by: McGeeky | last post by:
Is there a way to get a user control to remember its state across pages? I have a standard page layout I use with a header and footer as user controls. Each page uses the same layout by means of...
11
by: Joseph Geretz | last post by:
I've been looking at two approaches for the maintenance of Session state for a Web Service application. One approach uses the old familiar Session object which I've used in the past for Web...
3
by: sheldonlg | last post by:
In some code I inherited there is use of the TDC control to display table data. In trying to fix a problem, I put a couple of session variables into the module that is specified by the DataURL...
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...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.