It is currently Fri Mar 29, 2024 10:35 am


All times are UTC


Forum rules


Please click here to view the forum rules



Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: PHP sessions... again
PostPosted: Sat Nov 05, 2005 7:53 pm 
Noobie
Noobie

Joined: Sat Nov 05, 2005 5:01 pm
Posts: 4
Hello, I've read a number of posts on this issue but still don't know if it has been resovled.

I have the session_start() as the first line of the page. It is my one and only page. The page is refreshed as a result of a form submit action (not that has anything to do with it). At the start of execution I can see the variables I want to save in session variables and I can they are changed at the end of the exectution. When the page is refreshed, these variables are cleared.

I saw a previous post where a similar problem was reported.
http://forum.100webspace.com/viewtopic. ... ht=session

It seems like I have same issue. Has it been resolved?? Thanks,

Slawek


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 05, 2005 9:54 pm 
Are cookies enabled on your browser? Also, if you are behind a router with NAT configured, this may affect it.


Top
  
 
 Post subject:
PostPosted: Sun Nov 06, 2005 3:05 am 
Noobie
Noobie

Joined: Sat Nov 05, 2005 5:01 pm
Posts: 4
Yup, I'm behind a router. How can I work around this? Thanks,

Slawek


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 06, 2005 6:02 pm 
Please open a support ticket from within your control panel


Top
  
 
 Post subject:
PostPosted: Tue Feb 14, 2006 5:08 am 
Noobie
Noobie

Joined: Fri Dec 23, 2005 5:12 am
Posts: 13
Location: WI, USA
Sorry to drag up an old topic, but I'd rather do this than start my own.

I've had this problem with an old site of mine, where the SESSION data seemed to suddenly get cleared from page to page. I was never able to resolve the problem.

Now, once again I am resorting to using SESSIONS heavily for a log-in type part of my site. This time I can't even get my sessions to work once.

I go to my first page that has SESSIONS, and my page goes nuts and says:

Quote:
XML Parsing Error: junk after document element
Location: http://joelson.farvista.net/joelson/
Line Number 3, Column 1: <b>Warning</b>: session_start(): Cannot send session cookie - headers already sent by (output started at /home/www/joelson.......


Now, I have my website and sessions working PERFECTLY on my local machine and server. There are no problems at all. However, when the pages are on 100webspace, the sessions are all of a sudden being sent AFTER other page output has begun...

Hmmm... I wonder what this could be :roll:

I'm putting my preliminary blame on the free ads. No, I have nothing wrong with ads on my free pages, and I like how unobtrusive they are. However, the code for the ads is wildy invalid for the XHTML standards I code with.

However 100webspace inserts these ads into your site, they are apparently adding them extremely close to, if not at, the top of your page. This may be showing up before any of your PHP code and session variables. This beginning of output on the page prevents PHP from changing any session data/cookies. That (in my educated guess) is why session data is lost over pages - the ads prevent the sessions from working correctly.

Now, you might wonder why your data is lost but you don't get the nasty error message I have. The simple answer to that is I send my webpages with the MIME type "application/xhtml+xml," which forces compatible browsers to parse pages correctly. If you are using Internet Explorer 6.0 or below, the pages (and ads) will display fine, except the sessions won't work. However, if you are using a web standards browser such as Opera, Firefox (my favorite 8) ), or [finally compliant] IE 7 (beta), then "application/xhtml+xml" activates the XML parsing in the browser, and it will pop up with the error I receive.

In short, if your sessions are not working, it is most likely because of the free ads placed on your page by 100webspace. Until 100webspace cleans up the code and how they insert it into pages, this is simply another thing that will linger by and irk people who write clean, valid code. (I wrote some other stuff on the ads in this locked topic.)

But, since I didn't intend this as SIMPLY a rant against the invalidly-written ads post (:lol:), has anyone out there gotten their session variables to work correctly (on the free hosting)? If so, how?

_________________
"I realize my fears might never be allayed, and so I close, realizing that perhaps the ending has not yet been written."
"May the Force be with you."


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 14, 2006 2:12 pm 
Posts like crazy!
Posts like crazy!

Joined: Mon Sep 26, 2005 5:03 pm
Posts: 204
Location: The Netherlands
It works here.. by just doing as you should do it.. Never had problems with it..
The ads get added after the <body> tag so its not the ads unless you don't got a <body> tag, or "session_start()" is after the body tag.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 14, 2006 5:28 pm 
Posts like crazy!
Posts like crazy!

Joined: Mon Sep 26, 2005 5:03 pm
Posts: 204
Location: The Netherlands
lol yeah stupid mistake of mine =p


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 15, 2006 1:51 am 
Noobie
Noobie

Joined: Fri Dec 23, 2005 5:12 am
Posts: 13
Location: WI, USA
Beta... beta preview... close enough.
I acknowledge my mistake. :oops: :lol:

My sessions worked fine on my pages on my local computer, but when I uploaded them to 100webspace (farvista), then it started causing the error. I don't get quite why it would suddenly show up when on 100webspace. The only difference between the two places (where I develop my site and where I upload it to) is the ads on 100webspace.

My session_start() is before the <body> tag.
It was also before the DTD, <html>, and everything else... almost.

I went back just now and checked my pages. There was only one type of "output" to the page before my session_start() - I had PHP print out <?xml version="1.0" encoding="utf-8"?>. However, having this before my session_start() caused no errors on my local machine. However, I tried moving it just in case. Now it is suddenly - on my local computer - popping up with the error "XML Parsing Error: xml declaration not at start of external entity."

Now I am confused as to what to do. If I have the XML written out before the session_start(), then it doesn't seem to work on 100webspace. If I move the session_start() before the XML declaration, then it stops working on my local computer.

Here is specifically what I have at the beginning of my pages (after moving the XML declaration after the session_start), if it will help:

Code:
<?php
require("../mimetype.php");
session_start();
?>

<?php
echo"<?xml version=\"1.0\" encoding=\"utf-8\"?>";
if (!isset($_SESSION["login"])) {
    $_SESSION["login"] = 0;
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<head>, <body>, rest of page, etc.



The page mimetype.php is used to send the page as "text/html" or "application/xhtml+xml" depending on if the viewing browser supports it. The page simply has the following code:

Code:
<?php
if ( isset($_SERVER["HTTP_ACCEPT"]) and stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") ) {
    header("Content-type: application/xhtml+xml; charset=utf-8");
    header("Vary: Accept");
}

else if (stristr($_SERVER["HTTP_USER_AGENT"],"W3C_Validator")) {
    header("Content-type: application/xhtml+xml; charset=utf-8");
    header("Vary: Accept");
}

else {
    header("Content-type: text/html; charset=utf-8");
    header("Vary: Accept");
}
?>


What can I do so that it won't pop-up errors saying the XML declaration needs to be at the top AND that it won't pop-up errors (on 100webspace) saying that I was trying to change session header-cookies after output had been printed?

_________________
"I realize my fears might never be allayed, and so I close, realizing that perhaps the ending has not yet been written."
"May the Force be with you."


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 15, 2006 2:08 am 
Noobie
Noobie

Joined: Fri Dec 23, 2005 5:12 am
Posts: 13
Location: WI, USA
And then fiddling around a few minutes later, I may have solved my own problem...

I moved the session_start(); into the mimetype.php page and removed it from all the other pages that had it at the start. (This is not my ideal solution, as I only want a small part of my site to use session variables - now all pages get session_start() with the mimetype page, and I don't really want to have to make another mimetype page just for the session part of the site. Well, I guess I'm whining - making another mimetype.php page wouldn't be hard at all.) Anyway, not being 100% certain how sessions, headers, and other bits of the Internet work, it apparently works when I set some headers and set the cookie (cookie-header they called it in the error messages) session variable at the same time, rather than set some headers (for my mimetype) in one part of the page, then shortly after try and set the session cookie.

I'm not sure why it worked on my computer, and not on 100webspace the way I had it before, but at least I now have it to work on both.

EDIT: The final code that is working for me both locally and on 100webspace:
Code:
<?php require("../mimetype.php"); ?>
<?php echo"<?xml version=\"1.0\" encoding=\"utf-8\"?>"; ?>

The session_start(); is within the mimetype.php page.

Oh, if you are wondering why I am using PHP to print out the XML declaration, it is because I could not get PHP to stop thinking that the "<?" was a short-tag, even though it is clearly turned OFF in my php.ini file.

_________________
"I realize my fears might never be allayed, and so I close, realizing that perhaps the ending has not yet been written."
"May the Force be with you."


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ]  Moderators: fhmagic, KJ, Moderators, Support Team

All times are UTC


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
100WebSpace © 2011