Page 1 of 1

Passing data with PHP

Posted: Fri Jun 30, 2006 4:23 am
by stampi
I want to find out if there are other ways to pass data to the browser except the $_GET and $_POST methods. If there was something not as ugly as the $_GET string and without the $_POST notification for resending data after refreshing, that would be the best. I was wondering if there is a way to pass data structures for example or something like this. Otherwise I will put up with using the POST, but thanks in advance for any replies!

S.

Posted: Fri Jun 30, 2006 7:58 am
by thomas777neo
I personally think it is of good practice to use $_GET and $_POST, to identify where the variables come from. You could use the variable name if register globals is on. e.g. $_GET['variable'] would be represented as $variable. But this is a very poor way of coding. If you dont want to jump between the $_GET and $_POST, you could use $_REQUEST, which represents both.

$_GET used to it.

Re: Passing data with PHP

Posted: Fri Jun 30, 2006 8:43 am
by aerodromoi
stampi wrote:I want to find out if there are other ways to pass data to the browser except the $_GET and $_POST methods. If there was something not as ugly as the $_GET string and without the $_POST notification for resending data after refreshing, that would be the best. I was wondering if there is a way to pass data structures for example or something like this. Otherwise I will put up with using the POST, but thanks in advance for any replies!

S.
(Session) cookies?
However, not all users accept cookies, so you'll have to check that first.

Posted: Fri Jun 30, 2006 8:57 am
by Luke
You mean pass data to the server?

Posted: Fri Jun 30, 2006 9:37 am
by Jenk
You can 'tidy' the query string to an extent using mod_rewrite (plenty of discussions about mod_rewrite on these forums) so that http://www.example.com/index.php?foo=bar&bar=foo can become http://www.example.com/foo/bar or similar.

Another way, is to make good use of AJAX, so that in particular situations, the address bar on the clients browser doesn't change, but you can still continue to use 'ugly' query strings to your hearts content.

I'm not 100% sure if you can use POST data with AJAX, though. Would certainly be nice if you can.

Posted: Sun Jul 02, 2006 4:48 am
by stampi
Thanks for all replies so far, AJAX and Cookies are good suggestions, however I don't want to lose, important in my case, 10 or so percent users that are Java incompatible or those that won't have their browser set to accept cookies. Using $_REQUEST won't help either, because the $_GET query strings will still appear and the resending data notification(which wouldn't be a security problem, anyway) will also pop up, so I guess it is not a solution at all. I will give it a while to think about it and in the end I guess I will be $_POST-ing.

S.