Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't access my session variables

Status
Not open for further replies.

mpopnoe

Programmer
Feb 28, 2002
47
US
First off, I have tried registering variables using session_register and $HTTP_SESSION_VARS and have only been able to use session_register (eventhough I've been changing the INI parameters as instructed in the php manual at php.net).

I have been able to register variables and can see the file in my temp folder and verify that the values are in there. When I try to use that session variable on another page the variable is null. Do i have to somehow use the session name or ID to reference the file where my session vars are stored? I am using IIS5 on Win2000. I'm using POST instead of GET on my forms and most of my pages post back to themselves so I can use fewer pages. Is this possibly the problem? Any help/advice would be great :)

thanks,
mike
 
Are you starting your scripts with something like:
Code:
session_name("MySessionID");
session_start();
This needs to be on every page that requires access to the session vars. Also, are you using 'transparent' SIDs, or passing them manually? If manually, then adding the following to your links may help:
Code:
<A HREF=&quot;next.php<?=SID?&quot;?MySessionID=&quot;.SID:&quot;&quot;?>&quot;>Next</A>
or a similar hidden variable on your forms.

Another pitfall is accessing session variables across domains - if this is the case with you then post here for more info.

-Rob
 
I tried using
session_name(&quot;name&quot;);
session_start();
before each script and am still having trouble. On the page where I am registering the variable I have tried starting the session and giving the session name like this:
<?php session_start();
session_name(&quot;name&quot;);
session_register(&quot;var&quot;);
$var = &quot;123&quot;;
?>

then on the page I am trying to access the variable I'm doing this:

<?php session_name(&quot;name&quot;);
session_start();
echo $var;
?>

The session_start() function creates a new session everytime I use it so my temp folder ends up with two session files. Do you know what I am doing wrong? Thanks alot for your help Rob!! Ohh, I must be using transparent SIDs (I am not passing the SID name in the URL). Is that what you mean by transparent and manual?

mike
 
Whenever I place session_start() at the beginning of a script it creates a new session rather than recognizing the current session. Any tips??

mike
 
Try this:

Don't use the session name function on the destination page.
Also use the $_SESSION array rather the variable directly (I am assuming that you are using PHP 4.1.0 or later).

<?php
session_start();
echo $_SESSION[&quot;var&quot;];
?>

This will also allow you to turn off register_globals in php.ini and close a potential security hole.
 
Thanks for the help. My problem is still with the session_start function. Whenever I call it it creates a new session. Do I need to check session_starts return value to avoid creating a new session? I had to change the path for where my session files are stored. Is there something else I need to change in the INI file that might be the reason for this problem? I am sending my session info to a temp folder within my web directory. Should I be saving these elsewhere?
 
Thanks for all you help, I finally got it working. I needed to append the SID to the url eventhough I have trans_id set in the INI file. I had tried this before but used PHPSESSID instead of SID so it didn't work and instead of troubleshooting it I moved on.

thanks again :)

mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top