Solved

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

Posted on 2007-11-16
11
589 Views
Last Modified: 2010-04-21
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
Comment
Question by:FrankTech
  • 6
  • 5
11 Comments
 
LVL 21

Expert Comment

by:nizsmo
ID: 20301651
<?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
 
LVL 21

Expert Comment

by:nizsmo
ID: 20301655
correction:

<?php phpinfo(); ?>
0
 

Author Comment

by:FrankTech
ID: 20301693
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 21

Expert Comment

by:nizsmo
ID: 20301722
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
 

Author Comment

by:FrankTech
ID: 20301764
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
 
LVL 21

Expert Comment

by:nizsmo
ID: 20301810
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
 

Author Comment

by:FrankTech
ID: 20301872
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
 
LVL 21

Accepted Solution

by:
nizsmo earned 250 total points
ID: 20301903
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
 

Author Comment

by:FrankTech
ID: 20301930
OK. Thanks for your help.
0
 

Author Closing Comment

by:FrankTech
ID: 31409671
The problem sort of resolved itself, but it appears there could be an intermittent problem, which the expert has helped me to notice.
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20301935
glad to be of assistance :)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question