[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 598
  • Last Modified:

Session Variables Not Working on UNIX Server, Although They Work in Same PHP Scripts on WAMP Localhost

I built a PHP application on WAMP localhost, then tranferred it to a commercial UNIX server. Although session variables worked fine on the localhost, they don't work on the UNIX server. Why?
   I'm using the common sessions code, like:
First Page:
         session_start();
         $_SESSION['Var'] = "a_string";
        
PAGE 2 (linked from page 1)
         session_start();
         $Var = $_SESSION['Var'];

If I echo the $Var on page 2 on the WAMP localhost, the value is printed perfectly.  But when the same script runs on the UNIX server, $Var is empty.  What should I do?
0
FrankTech
Asked:
FrankTech
  • 6
  • 5
1 Solution
 
nizsmoDeveloperCommented:
<?php phpinfor(); ?>

can you check here to see if session is enabled?

SHould have something like this:
session
Session Support       enabled
Registered save handlers       files user sqlite
Registered serializer handlers       php php_binary wddx

Directive      Local Value      Master Value
session.auto_start      Off      Off
session.bug_compat_42      On      On
session.bug_compat_warn      On      On
session.cache_expire      180      180
session.cache_limiter      nocache      nocache
session.cookie_domain      no value      no value
session.cookie_httponly      Off      Off
session.cookie_lifetime      0      0
session.cookie_path      /      /
session.cookie_secure      Off      Off
session.entropy_file      no value      no value
session.entropy_length      0      0
session.gc_divisor      100      100
session.gc_maxlifetime      1440      1440
session.gc_probability      1      1
session.hash_bits_per_character      4      4
session.hash_function      0      0
session.name      PHPSESSID      PHPSESSID
session.referer_check      no value      no value
session.save_handler      files      files
session.save_path      c:/wamp/tmp      c:/wamp/tmp
session.serialize_handler      php      php
session.use_cookies      On      On
session.use_only_cookies      Off      Off
session.use_trans_sid      0      0
0
 
nizsmoDeveloperCommented:
correction:

<?php phpinfo(); ?>
0
 
FrankTechAuthor Commented:
Yes, sessions appear to be enabled. Here's the result from the UNIX server:

Session Support  enabled  
Registered save handlers  files user sqlite  
Registered serializer handlers  php php_binary  

Directive Local Value Master Value
session.auto_start Off Off
session.bug_compat_42 On On
session.bug_compat_warn On On
session.cache_expire 180 180
session.cache_limiter nocache nocache
session.cookie_domain no value no value
session.cookie_httponly Off Off
session.cookie_lifetime 0 0
session.cookie_path / /
session.cookie_secure Off Off
session.entropy_file no value no value
session.entropy_length 0 0
session.gc_divisor 100 100
session.gc_maxlifetime 1440 1440
session.gc_probability 1 1
session.hash_bits_per_character 4 4
session.hash_function 0 0
session.name PHPSESSID PHPSESSID
session.referer_check no value no value
session.save_handler files files
session.save_path /tmp /tmp
session.serialize_handler php php
session.use_cookies On On
session.use_only_cookies Off Off
session.use_trans_sid 0 0
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
nizsmoDeveloperCommented:
The only difference i suspect is:
session.save_path      c:/wamp/tmp      c:/wamp/tmp

and
session.save_path /tmp /tmp

does your tmp folder exist?
0
 
FrankTechAuthor Commented:
It's a shared host, and there is a /tmp at:
       /usr/tmp

My directory is
      /usr/home/myaccount
and the www directory is:
     /usr/www/users/myaccount

There is no "tmp" directory visible in my own subdirectories, but I've always assumed it somehow used a shared
      /usr/tmp
0
 
nizsmoDeveloperCommented:
can you have custom php.ini?

If you can, maybe change this to
session.save_path = "/usr/tmp"

i guess there's no harm in trying, as you can just change it back if it doesn't work.

Also are you able to look into your error log and see what it is displaying?
0
 
FrankTechAuthor Commented:
I can't have a custom php.ini on the UNIX host.

I looked in the www logs and did not see anything related to this problem. It wasn't an error log. I can't seem to find error logs. Maybe I'm not allowed to access them.

But here's something strange:  without doing anything different (just running the same script as before), the session variable suddenly seems to be working on the UNIX host.

That's good news. But it's also sort of scary, because it sounds like there might be some kind of intermittent error.
0
 
nizsmoDeveloperCommented:
really? hmmmmmmm how weird.

My suggestion is to contact the web hosting company, and state to them this possible intermittent issue, they should be able to give you support and recent issues with session variables on their server. As far as I can see, nothing is wrong with the settings (as they should already be setup on their server properly and all ready to go). Maybe it was a faulty setting which they happen to fix just then?

You never know...
0
 
FrankTechAuthor Commented:
OK. Thanks for your help.
0
 
FrankTechAuthor Commented:
The problem sort of resolved itself, but it appears there could be an intermittent problem, which the expert has helped me to notice.
0
 
nizsmoDeveloperCommented:
glad to be of assistance :)
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now