tags:

views:

105

answers:

5

I'm not exactly sure the question I should be asking. Sorry!

I'm working on re-doing my web site so as to be using PHP5. The server lives in a buddy's basement and I just ssh in to do my coding and view the pages just like any other page out there.

I keep track of login details in $_SESSION.

When I'm sitting at my home machine I can log into the site and everything is as I expect it in terms of the SESSION being available on all pages. When I log in on my work machine, I get a successful log in and can see the SESSION variables, but as soon as I go to another page the SESSION is gone as evidenced in session_id().

My previous web site built in PHP4 (and tweaked to keep PHP5 happy) does not exhibit this behavior allowing me to log in as expected at either location before and after the change to PHP5.

I guess I'm just looking for a clue as to what to explore next... Of all the puzzles I've encountered while teaching my self to code this one appears on the face, just crazy.

A: 

Do you make use of session_start() in your various php files ?

JonH
He said it works fine at home.
Byron Whitlock
A: 

It could be that the computer at work isn't supporting session cookies. It's been a while since I last read about PHP Sessions, but from what I remember...

  1. session_start() is called.
  2. php checks to see if the browser has sent a cookie to the server (a unique identifier needs to be supplied.
  3. if so, it then checks checks on the server for a file with the name of the session id
  4. if successful, it parses the file and sets the variables into the $_SESSION array

Notice that step one of this process is to actually start the session with session_start() this needs to be called before any output at all.

Have you got session_start() before output?

jakeisonline
I definitely have session_start() the very first thing -learned that the hard way.I think I have to say the computer at work must be supporting session cookies because my old site uses SESSION and works happily. It's this inconsistancy that's got me all wound up...
Humpton
One thing you could do is use Firebug to see what's happening with HTTP requests, this might reveal something (or it might reveal nothing..) - the old site, different server? Also, this new server you're using in your buddy's basement, do you live with him? On the same connection?
jakeisonline
Both sites live on the same server in the same basement (not my house) on the same connection...
Humpton
Well that's pretty odd then. If the PHP Project isn't too big I'd be happy to take a look at it offline, just stick a me@ before the website address on my profile, I'll reply ASAP.
jakeisonline
+2  A: 

I think Jake is on to something about the cookies. Make sure your browser at work is set to accept cookies from that domain. Make sure there isn't any antivirus/antimal-ware that has disabled this. I'd use fiddler to watch the traffic and headers on your work machine, and your home machine. you should be able to quickly spot the difference since it sounds like a client issue.

Byron Whitlock
I guess that's what I get for commenting my down votes
Byron Whitlock
Commenting downs should come with some sort of buffer to prevent 'revenge' down votes - but that's for another time
jakeisonline
+1 nothing wrong with the answer, could even solve the problem
Jacco
A: 

One way to get around this problem could be to store your sessions in a database.

This DevShed article by Rich Smith is a good place to start: Storing PHP Sessions in a Database

The session is no longer saved as a file on the server, but rather an entry in the DB, and should solve any cookie issues.

CommissarXiii
Changing the location of stored data on the server will not change any cookie related issues.
Jacco
Yup, you're right - I was way off! Setting session.use_cookies = 0 in php.ini and passing the session id as a GET attribute would fix that though. Good call.
CommissarXiii
A: 

Are the settings in php.ini for session.auto_start the same in both ini's?

See http://de3.php.net/manual/en/session.configuration.php#ini.session.auto-start

powtac