Solved

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

Posted on 2007-11-16
11
583 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Wordpress Query 1 35
PHP Curl Setup Option 4 33
Re-imbursement Claim System 3 25
selecting date modified field from a table 2 0
Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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 …

746 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now