Trium918 Posted May 30, 2007 Share Posted May 30, 2007 I have created 30 pages and counting without using a single $_GET variable. I guess you can say that I really donnot have an understanding of how to use and when to use the $_GET variable. Which is true because http://php.net doesn't help; therefore, I am asking for one of you to go into more detail then what other websites have to offer. Thanks!' Some you are probably wondering the same thing, I hope. Quote Link to comment Share on other sites More sharing options...
Wildbug Posted May 30, 2007 Share Posted May 30, 2007 From: http://us.php.net/manual/en/reserved.variables.php#reserved.variables.get "An associative array of variables passed to the current script via the HTTP GET method. Automatically global in any scope." Those are variables passed by URLs such as http://whatever.com/script.php?this=that&id=2, otherwise known as the HTTP GET method (as opposed to POST). Thus, within script.php, $_GET['this'] = "that" and $_GET['id'] = 2. Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted May 30, 2007 Share Posted May 30, 2007 The $_GET method works with the URL instead of post data. Lets take this URL for example: www.example.com/index.php?user=Trium918 This could be useful if you had a profile for your users and you got whos profile to display from the URL. You would get the persons name with the $_GET method like so: <?php $user = $_GET['user']; echo $user; //will print "Trium918" ?> You could now use this username from the URL to pull information on the user from the database. <?php $user = $_GET['user']; $sql = mysql_query("SELECT name, address, country, age FROM users WHERE username='" . $user . "'"); if (mysql_num_rows($sql) > 0)){ //print all the users information here } else { echo "No such user"; } ?> That is just one example out of many...hopefully that clears it up a bit. Quote Link to comment Share on other sites More sharing options...
marf Posted May 30, 2007 Share Posted May 30, 2007 $_GET i find I use only when making pages with search queries, because it doesn't matter if the user can see that in the top browser bar. Also makes clicking the 'back'' button more friendly instead of that message when using POST pops up. Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted May 30, 2007 Share Posted May 30, 2007 @marf - Thats why you put this bit of code at the top of your scripts: header("Cache-control: private"); Quote Link to comment Share on other sites More sharing options...
per1os Posted May 30, 2007 Share Posted May 30, 2007 @marf - Thats why you put this bit of code at the top of your scripts: header("Cache-control: private"); If that is true (which I will be testing when I get home) you could of saved me headaches years ago with this stupid post problem. I will be running tests later tonight on it. Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted May 30, 2007 Share Posted May 30, 2007 Did the trick for any website I have used it on =] Quote Link to comment Share on other sites More sharing options...
Trium918 Posted May 30, 2007 Author Share Posted May 30, 2007 Thanks to all! I have another question. Is it possible to write an entire website without the use of $_GET? What does the code below prevents? <?php header("Cache-control: private"); ?> Quote Link to comment Share on other sites More sharing options...
Wildbug Posted May 30, 2007 Share Posted May 30, 2007 It's possible to write an entire website without PHP. Likewise, there are plenty of PHP features it's possible not to use, including GET methods. Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted May 30, 2007 Share Posted May 30, 2007 Cache-control: private Indicates that all or part of the response message is intended for a single user and MUST NOT be cached by a shared cache. This allows an origin server to state that the specified parts of the response are intended for only one user and are not a valid response for requests by other users. A private (non-shared) cache MAY cache the response. Note: This usage of the word private only controls where the response may be cached, and cannot ensure the privacy of the message content. Whatever that means...haha. I basically use it so that when you click back on your browser after submitting post data it doesn't give you a popup telling you about it then forces you to refresh the page and resubmit everything. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.