?
Solved

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

Posted on 2007-11-16
11
Medium Priority
?
596 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
Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

 
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 1000 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

7 Extremely Useful Linux Commands for Beginners

Just getting started with Linux? Here's a quick start guide that has 7 commands that we believe will come in handy.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

770 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