Solved

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

Posted on 2007-11-16
11
594 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP Curl Problem 10 73
Compiling PHP with Curl plus protocols 8 48
SSL unsecure page mystery 17 46
foreach loop to only capture results that are greater than 0 16 37
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
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 look for a specific file type in a local or remote server directory using PHP.

734 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