p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: why, randomly, PHPSESID in the url?


Message #1 by spam@k... on Tue, 24 Sep 2002 15:21:46 -0500
Randomly, on no particular page, the PHPSESID suddenly shows up in the URL. I suddenly end up with
something like this: 

http://www.alternativestopaving.monkeyclaus.org/index.php?articleId=2&PHPSESSID=81e7be9524880f4f542c9bdde51b8560


On most pages, however, the PHPSESID does not show up in the URL. I don't want it there as it makes the url look frighteningly long.
If its there, does that mean I have some code that puts it there, or does PHP itself sometimes do this? I usually build links on
this site like this:

global $PHP_SELF:
$self = $PHP_SELF;
$self .= "?articleId=";
$self .= $articleId; 






Message #2 by "Nikolai Devereaux" <yomama@u...> on Tue, 24 Sep 2002 13:40:11 -0700
> Randomly, on no particular page, the PHPSESID suddenly shows up in
> the URL. I suddenly end up with something like this:
>
> http://www.alternativestopaving.monkeyclaus.org/index.php?articleId=2
> &PHPSESSID=81e7be9524880f4f542c9bdde51b8560

Well, in order to persist the session, you need to pass the session ID across
your pages.  If you have enabled the trans-sid feature in PHP.ini (the default
is on, i believe), then PHP does this for you.  However, I think PHP adds a
hidden input field to all forms and an extra GET parameter to all links for a
generated page which begins a session.

In that sense, the PHPSESSID shouldn't show up randomly.  It should appear on
the *second* page you hit on your site, because the sessid was generated during
the first.


btw, you can change these four lines:

> global $PHP_SELF:
> $self = $PHP_SELF;
> $self .= "?articleId=";
> $self .= $articleId;

to this:

$self = $_SERVER['PHP_SELF'] . "?articleId={$articleId}";


take care,

nik

Message #3 by spam@k... on Wed, 25 Sep 2002 13:38:42 -0500
> In that sense, the PHPSESSID shouldn't show up randomly.  It should appear on
> the *second* page you hit on your site, because the sessid was generated during
> the first.

You're right. It seems to always be the second page. 





> > global $PHP_SELF:
> > $self = $PHP_SELF;
> > $self .= "?articleId=";
> > $self .= $articleId;
> 
> change to this:
> 
> $self = $_SERVER['PHP_SELF'] . "?articleId={$articleId}";


I can't, since that won't work pre- PHP 4.1. I've built a simple content management system which I've now installed for 5 clients
plus myself. PHP is fairly cross-platform, but even so minor problems crop up, like 'QUERY_STRING' becoming "REDIRECT_QUERY_STRING'.
And some of the sites are hosted in pre 4.1 environments. You've recommended some great functions that would allow the transition to
be seemless, and I've saved your old letters with the intent of implementing them at some point. It is merely a matter of lacking
time that has kept me from doing so. 

take care

lawrence




  Return to Index