p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: Anyone seen SID?


Message #1 by "Bob Dolan" <rdolan@n...> on Fri, 20 Sep 2002 15:33:54
I have been unable to pass the session ID in the URL using =SID.  [For 
that matter, I can't echo or assign SID.]

My workaround was defining a SID equivalent with  
$myid = "PHPSESSID=" . $PHPSESSID; 

and then using  href="someform.php?<?php echo $myid?>"  in the link.

This floats the boat for the moment, but I wonder if I am just missing 
SID, or if he didn't make the scene until after my 4.0.1pl2 version of 
PHP.  [As you can see, I'm already using the long form of echo because the 
short form didn't make my release.]

Also, anyone see any 'gotchas' in my workaround?  Right now the $myid 
variable is assigned in the core script, and the link is contained in an 
included script.  I worry about that, but I'm the nervous type.

All clues and comments appreciated,

Bob

Message #2 by "Nikolai Devereaux" <yomama@u...> on Fri, 20 Sep 2002 11:21:29 -0700

First of all, I should point out that SID (if defined) is a *constant*.  You
can't assign to it.

This also means it's not a variable -- that is, don't make the common
mistake of writing "echo $SID;".  All you need is "echo SID;"



> Also, anyone see any 'gotchas' in my workaround?  Right now the $myid
> variable is assigned in the core script, and the link is contained in an
> included script.  I worry about that, but I'm the nervous type.

Well, you're assuming that the session.name line in php.ini will always be
"PHPSESSID".  That's really up to the sysadmin who maintains the PHP on the
server.  A more robust solution would be to get the session name dynamically
through the use of the session_name() function.

At the top of your script (or rather, in a separate file that's required by
all your scripts), do this:

if(! defined('SID'))
{
  define('SID', session_name() . '=' . ${session_name()});
}

if that doesn't work, try this:

if(! defined('SID'))
{
  $sess_name = session_name();
  define('SID', $sess_name . '=' . $GLOBALS[$sess_name]);
}



Continuing...

From http://www.php.net/session (long page, lots of info)

<quote>
Predefined Constants

The constants below are defined by this extension, and will only be
available when the extension has either been compiled into PHP or
dynamically loaded at runtime.

  SID (string)
    Constant containing the session name
    and session ID in the form of "name=ID".
</quote>



And finally, I have to ask... why not upgrade your PHP?


Take care,

nik

Message #3 by "Bob Dolan" <rdolan@n...> on Fri, 20 Sep 2002 23:19:33
Nik replied:

>First of all, I should point out that SID (if defined) is a *constant*.  
>You
>can't assign to it.

I know, I said it wrong.  I wasn't assigning something to SID, I was 
assigning SID to $something;.  On the echo side, I tried them all.  My 
conclusion was that the SID constant is not defined on my system.

Then Nik gave me this:
> Also, anyone see any 'gotchas' in my workaround?  

PHPSESSID".  That's really up to the sysadmin who maintains the PHP on >the
server.  A more robust solution would be to get the session name 
dynamically
through the use of the session_name() function.

At the top of your script (or rather, in a separate file that's required by
all your scripts), do this:

if(! defined('SID'))
{
  define('SID', session_name() . '=' . ${session_name()});
}

if that doesn't work, try this:

if(! defined('SID'))
{
  $sess_name = session_name();
  define('SID', $sess_name . '=' . $GLOBALS[$sess_name]);
}

That's really great, and was just what I was looking for.


Then Nik offered
>Continuing...

>From http://www.php.net/session (long page, lots of info)

><quote>
>Predefined Constants

>The constants below are defined by this extension, and will only be
>available when the extension has either been compiled into PHP or
>dynamically loaded at runtime.

>  SID (string)
>    Constant containing the session name
>    and session ID in the form of "name=ID".
></quote>

I'm not sure how I know what constants are defined on my system, but I'm 
off the php.net to try and figure that out.  Seems like a basic thing I 
should know.

And finally, [nik poses]

>I have to ask... why not upgrade your PHP?

Why not indeed?  I have a "Freedom 250" server from Interland.  They are 
telling me that they are upgrading all of their clients with this product 
to a 'new level'.  This is supposed to happen sometime this month.  Before 
this thread, I didn't give much thought to the PHP version that was 
included in the 'upgrade'.  Now, I have a new topic the review with my 
Account Rep.

As a side note, the 'Freedom 250' server does not offer 'root' access to 
the freeBSD operating system.  If I upgrade my version of PHP on my own, I 
lose all PHP support from Interland.  If the promised upgrade does *not* 
upgrade my PHP version, I have the options of upgrading PHP on my own, or 
going to another 'package', either with Interland or with others.  I would 
love to hear from others who have ISPs that understand the needs of PHP 
programmers.

TIA -- and thanks to nik

Bob Dolan
rdolan@r...



  Return to Index