Page 1 of 1

what is the best way to pass variables between pages?

Posted: Sun Sep 19, 2010 5:22 am
by cneeds
Hi

In your opinion what is the best way to pass variables between pages?

I'm storing everything in $_COOKIE but it's really quite messy.

On the other hand I can't get $_SESSION or $_SERVER to work.

Has anybody written a definitive paper on how best to track variables between pages? It will be good for me to read that before I go too much further.

Chris

Re: what is the best way to pass variables between pages?

Posted: Sun Sep 19, 2010 7:58 am
by requinix
Depends on the situation; GET, POST, cookies, and sessions are all valid for some set of circumstances.
Though the session is generally easiest.
cneeds wrote:On the other hand I can't get $_SESSION or $_SERVER to work.
Oh really?

Re: what is the best way to pass variables between pages?

Posted: Sun Sep 19, 2010 4:08 pm
by cneeds
tasairis wrote:Oh really?
Yes, I didn't realise I had to session_start at the top of every page. In my simple brain once it's started it runs til it stops. Not so says php, life can never be that simple :cry:

Thank you for your time anyway 8)

Chris

Re: what is the best way to pass variables between pages?

Posted: Tue Sep 21, 2010 7:33 am
by cneeds
I resolved the problem by putting a path statement of "/" in my set cookie calls!!

Thanks for the help everyone.

Chris

Re: what is the best way to pass variables between pages?

Posted: Tue Sep 21, 2010 7:42 am
by josh
You should look into session.auto_start in the php.ini file.