what is the best way to pass variables between pages?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cneeds
Forum Newbie
Posts: 24
Joined: Tue Sep 14, 2010 1:39 am

what is the best way to pass variables between pages?

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

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

Post 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?
cneeds
Forum Newbie
Posts: 24
Joined: Tue Sep 14, 2010 1:39 am

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

Post 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
cneeds
Forum Newbie
Posts: 24
Joined: Tue Sep 14, 2010 1:39 am

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

Post by cneeds »

I resolved the problem by putting a path statement of "/" in my set cookie calls!!

Thanks for the help everyone.

Chris
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

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

Post by josh »

You should look into session.auto_start in the php.ini file.
Post Reply