Welcome to WebmasterWorld Guest from 54.166.178.177

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Valid Pages with PHP session enabled?

     
5:21 pm on Jul 7, 2002 (gmt 0)

WebmasterWorld Senior Member lorax is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Hola,
I have a page that uses a session. The session ID (PHPSESSID) is automatically added to the links where I'm passing a variable on the URL (example.php?var=value&PHPSESSID=75d1bac8ae12cde317e1cc55d6d58e6f). The validator is choking on the link. The doctype and namespace look like this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

Do I need to encode the URL using url_encode() or ??

5:34 pm on Jul 7, 2002 (gmt 0)

WebmasterWorld Senior Member nick_w is a WebmasterWorld Top Contributor of All Time 10+ Year Member



I don't think you'll be able to encode the url, but here is something I wrote to set a session only if the UA is nat a search engine:


<?
/* Use this to start a session only if the UA is *not* at search engine
to avoid duplicate content issues with url propagation of SID's */
$searchengines=array("Google", "Fast", "Slurp", "Ink", "Atomz", "Scooter", "Validator");
$is_search_engine=0;
foreach($searchengines as $key => $val) {
if(strstr("$HTTP_USER_AGENT", $val)) {
$is_search_engine++;
}
} if($is_search_engine==0) { // Not a search engine

/* You can put anything in here that needs to be
hidden from searchengines */
session_start();

} else { // Is a search engine

/* Put anything you want only for searchengines in here */
$foo=$bar;

} ?>

You can use it to include the 'Validator' as well.

Nick

6:31 pm on Jul 7, 2002 (gmt 0)

WebmasterWorld Senior Member lorax is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Ah hah! I thought you might be on-line Nick.

Good idea but what's the USER AGENT id for the W3C Validator (http://validator.w3.org)? "Validator" didn't do it because I'm still getting the error.

6:50 pm on Jul 7, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



W3C_Validator/1.183 libwww-perl
7:01 pm on Jul 7, 2002 (gmt 0)

WebmasterWorld Senior Member lorax is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Whoops - my mistake. I didn't wrap my session_register() declarations. Thanks both!

GB

7:12 pm on Jul 7, 2002 (gmt 0)

10+ Year Member



I am glad he was cause I looked at the question did a search but wasnt quite understanding the question still. My feable attempts at scripting doesnt include such things yet. I vote for Nick & jatar_K as Mods!
7:27 pm on Jul 7, 2002 (gmt 0)

WebmasterWorld Senior Member lorax is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Knowles,
If you have sessions enabled session_start(), the web server assigns a session ID (SID) to each visitor - which includes SEs, validators, as well as browsers. In order to maintain the current session when a user clicks on a link, the SID is automatically appended to the URL. The format is "&PHPSESSID=somelongalphanumericcode". The problem is that the validator doesn't like the &.

So what Nick gave me is a chunk of code that identifies the validator before the session is enabled and prevents the session from starting. Which prevents the SID from being appended. Which, as far as the validator is concerned, is perfect. It only needs to look at my structure and content - not the variables I pass on the URL. Make sense?

9:03 pm on Jul 7, 2002 (gmt 0)

10+ Year Member



Thank you for explaining Lorax I have never used anything other than premade scripts that had anything cookies or sessions so I have never really learned about them.
9:41 pm on Jul 7, 2002 (gmt 0)

WebmasterWorld Senior Member nick_w is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Sessions are very cool. They actually set a cookie on the client-side if possible but will append the session id to the urls (including adding hidden fiels on forms) if the client will not except cookies.

One very common use of cookies is to store just an unique id for the user that relates to a databse record containing all of the users preferecnces/data.

Nick

11:59 pm on Jul 7, 2002 (gmt 0)

WebmasterWorld Senior Member lorax is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



I have never used anything other than premade scripts

Oh but you should try. Once you build something of your own creation - no matter how simple - you will begin to get the bug. With PHP there's very little you can't accomplish. BTW - for pre-assembled scripts you should add www.hotscripts.com to your bookmarks if you don't already have it there.
12:23 am on Jul 8, 2002 (gmt 0)

10+ Year Member



ohh I know that Lorax... I write scripts but never gotten into sessions and the such. I actually wrote one the other day cause someone needed it on here.
7:03 am on Jul 10, 2002 (gmt 0)

10+ Year Member



If you use &amp;PHPSESSID=.... instead of &PHPSESSID=.... in the link, the validator should stop complaining.

If the link is generated by the PHP's session module, you can fix it by putting this in your php.ini:

arg_separator.output = "&amp;"

If you don't have access to or don't want to use php.ini you can modify this setting in the very beginning of your script instead:

ini_set('arg_separator.output', '&amp;');

Hope this helps.

- Stig

7:52 am on Jul 10, 2002 (gmt 0)

WebmasterWorld Senior Member nick_w is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Good call stigsb!
I've been wondering if it was possible to change the way php does it.

I'm surprised they havn't altered in latest versions, they've been using <br /> in nl2br() for quite a while....

Nick

3:16 am on Jul 12, 2002 (gmt 0)

WebmasterWorld Senior Member lorax is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Brilliant stigsb!
I'll post a note to the host tonight! Thanks all.

GB.

 

Featured Threads

Hot Threads This Week

Hot Threads This Month