Re: Using Header() to pass information...

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

 



On Sat, April 22, 2006 10:15 am, Todd Cary wrote:
>    if ($send)
>      header("location: mypage.php?message=" . $message);
>
> the data ($message) is passed in the URL.  Is there a way to pass
> the data as though it was a POST method i.e. not in the URL?

Without copying and pasting a lot of bits and pieces from four other
posts...

#1.
Cramming stuff into $_POST is probably NOT a good idea, just on
general principle, that $_POST is supposed to have the stuff in it
that came from the browser.

If you are doing your sanitization/filtering/validation correctly, you
shouldn't even be READING $_POST after the first 3 lines of your PHP
code anyway.  (Okay, maybe first 10 lines.)

#2.
Definitely don't try to use Location: without the full http:// URL
You are only asking for grief.

#3.
If the mypage.php is on your own computer, you would probably be MUCH
better off to just include it instead of the other options given.

While you CAN cram the data into a $_SESSION and then send your
Location:, think about what that does:
1. Writes a bunch of data to hard drive in $_SESSION
Or to your db, which ends up on your hard drive anyway, most likely.
Okay, this bit could get real complicated and picuyane, but let's just
agree that it uses up not insignificant resources, no matter what your
session back-end.
2. Sends a response to the browser telling it to go look somewhere else.
3. The browser then has to request a new URL.
4. That then hits your HTTP server again, using up another HTTP
connection.
5. The web server then reads... mypage.php and executes it.

So, you can do all that, or you can skip to step 5 with an include.

Call me silly, but skipping steps 1 through 4, and not wasting all
those resources, sounds like a Good Idea to me.

You might maybe have to re-structure your application a bit.

Maybe mypage.php has to be re-written to not use $_POST necessarily,
but to use $_POST or some OTHER array, if that other array is defined.

But, still, your server will be a lot more zippy if you don't sprinkle
all these header("Location: ...") calls all over the place.


The other suggestion, of opening up a socket and doing the POST and
returning the data is good, *IF* mypage.php isn't on your server, and
you do not have an API from whomever provides that content.

Opening up a socket on your own server to POST data to yourself
instead of just doing an include... Well, it's not as bad as the
preceding, since your network lag is negligible when a machine talks
to itself, but you're still wasting HTTP and socket resources, so that
you can coax the web-server into reading and executing a PHP file,
when, again, you can just do step 5.

Disclosure:
When I first figured out the Location: header, I thought it was really
cool, and was going to structure my MVC (sort of, though I had no idea
it was called MVC then) application around that...

The longer you use header("Location: ...") the more you realize how
it's just not a substitute for a well-structured web application.

Just my 2 cents.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
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