note 57868 deleted from faq.html by jome
| From: | jome@php.net | Date: | Mon, 17 Oct 2005 16:14:36 +0000 |
| Subject: | note 57868 deleted from faq.html by jome | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-97122@lists.php.net to get a copy of this message | ||
Note Submitter: richard dot prangnell at ntlworld.com
Reason: useless
----
A Hiccup with PHP Sessions and the W3C HTML Validator
It is good practice to write HTML that passes the W3C HTML Validator with flying colors. It also
shows potential clients/employers that you can code properly. Unfortunately, for any HTML page
subject to tracking by a PHP Session, you can end up looking less than perfect in this regard
(unless url encoding of the session ID is disabled in the php.ini file, but the downside of doing
this is that anyone who has cookies turned off will not be able to interact with such a site).
This is because the W3C Validator does not accept cookies, so PHP automatically appends the
PHPSESSID to every local HTML hotlink on the page; the usual solution PHP uses to get around
browsers that have cookies disabled.
The problem is that the Validator treats the PHPSESSID as an "unidentified entity" - and
red-flags each occurrence as an error.
Without being really sneaky, such as turning off the session for any page served to the W3C site
(would I do such a thing?) the only answer I have found is to do page handoffs using JavaScript
instead:
First, the JavaScript:
function newpage(pageURL)
{
location.replace(pageURL);
}
Next, an example of the HTML work-around:
<a href="javascript:void(0)" onclick='newpage("./index.php"
title="Home Page")'>
This works because PHP only looks for the URL to append the PHPSESSID to in the 'href'
attribute of the <a> tag, and the above bit of code has moved it from there into the
'onclick' attribute.
If anyone has a better work-around, I'd love to know what it is.