Passing data with PHP

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
stampi
Forum Newbie
Posts: 2
Joined: Fri Jun 30, 2006 4:17 am

Passing data with PHP

Post 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.
User avatar
thomas777neo
Forum Contributor
Posts: 214
Joined: Mon Mar 10, 2003 6:12 am
Location: Johannesburg,South Africa

Post 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.
User avatar
aerodromoi
Forum Contributor
Posts: 230
Joined: Sun May 07, 2006 5:21 am

Re: Passing data with PHP

Post 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.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

You mean pass data to the server?
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post 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.
stampi
Forum Newbie
Posts: 2
Joined: Fri Jun 30, 2006 4:17 am

Post 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.
Post Reply