Re: Passing variables between pages

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 22 Sep 2008, at 15:08, tedd wrote:
At 2:47 PM +0100 9/22/08, Nathan Rixham wrote:
tedd wrote:
-Stut and Nathan:

The problem was not how to pass variables between requests, but rather how to variables between pages -- as the subject line indicates.

ahhhhhhhhhhhhhhhh! now I follow; and surely tedd what you say is indeed the best way of achieving this.

cheers for taking the time

Nathan:

No problem.

But here is what I would like you to consider, the next time you are thinking about using sessions to pass variables to the next script, try this technique instead.

You see, a few months ago I was working with another programmer who had a script that contained far more data than what I wanted to break down into sessions to pass to my script. So I tried this and to my surprise it worked flawlessly.

Then I thought "Where else could I use this?" and it seems that I can use this everywhere.

Now, I've had three hours of sleep, so my mind may be more fuzzy than usual, but I can't think of an example where I can't use this technique instead of using sessions.

If you can think of one, please tell me.

How about keeping track of a logged in user from request to request without resorting to adding data to the GET parameters, or using a form (ugh!), or a cookie (which is how I'd do it and is how sessions commonly do it).

Tedd, the "technique" you describe is as old as the hills and really only solves a fake problem that arises when you consider each PHP script to be "a page" and decide that you need to bounce off the browser to pass data from script to script. Once you graduate from that into thinking about each script as a piece of functionality rather than a page it's no big leap from there to including other scripts.

Consider this example... a lot of the pages on a site requires a user to be logged in. So at the top of each script that forms a page there is a chunk of code that checks to see if someone is logged in and displays the login form if they're not. Commonly there are two ways to do this, either with an HTTP redirect or by including the script that displays the form. Now consider that you want to pass the current URL to the login form so it can tell the form handler to redirect back here when login has been successful. What are the choices?

1) If doing an HTTP redirect you could add it as a GET variable which the login form script can check for and include in the login form to pass it to the handler.

2) If including the login form it will already have access to that variable so no "passing" needs to occur.

Which is better is a matter of taste, but either way once the user has been logged in you need something to go back and forth with each request to keep track of the fact that someone is logged in. Your technique does not solve this problem in any way I can see.

So essentially it comes down to semantics. What is a page? What is a script? What is a request? To me the three are completely different and treating them as such has great architectural and reuse benefits.

-Stut

--
http://stut.net/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux