SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2009
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Wink Hi, any expect pls come in to help...

    can i know that what the advantage for using $_GET, and usually it apply in which type of script??can i have some example for view,as i know that this was not suitable for login page that include "password" text... can anyone provide me some explanation because i am confused about it....thank in advance
    Dont blame, just start from today...
    Dont wait, do it start from this minit...

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Make a page like this;
    tester.php
    PHP Code:
    <?php
    print_r
    ($_GET) ;
    ?>

    <hr />
    <form method=GET action ="">
    Enter a password : 
    <input name="password" id="password" type="text" value="">
    <input type=submit>
    </form>
    <hr />
    Stick that in your web root directory and load it up, enter the password "secret" and you will see the GET method causes this to be seen in the BROWSER ADDRESS BAR.

    localhost/tester.php?password=secret

    and you should see some output from PHP saying it understood that the variable $_GET['password'] = "secret"

    Now, edit tester.php again and change the two GET instances to POST, and repeat the exercise. Your browser address bar should now show:

    localhost/tester.php

    But PHP still understands the incoming variable:
    $_POST['password'] = "secret"

    Using POST does not make your form any more secure, put that out of your head right now, you have simply made it less obvious to a casual looker.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2009
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    actually this is what i know but as i know that the $_GET function is to display in to the url for user easily to keep the url for favorites right??can i know it suitable apply in which condition?? got any script for an example??
    Dont blame, just start from today...
    Dont wait, do it start from this minit...

  4. #4
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    personal preference - GET for search forms, POST for most other forms.
    There is never a time you would need to bookmark a form submission!
    Passing data from links would always be GET so that would be bookmarkable, depends what it is you are doing and why.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  5. #5
    SitePoint Evangelist Waffles's Avatar
    Join Date
    Nov 2005
    Posts
    435
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    some instances where you'd use $_GET:


    Displaying data from a database table
    Most databases make use of a primary key to uniquely identify a given record. You can combine this ID and the use of $_GET to create dynamic content - i.e. selecting the article from the database where ID= $_GET['id']. In this way you can control what is shown to users to a certain extent.

    sitepoint uses this feature, the URL for this page is http://www.sitepoint.com/forums/showthread.php?t=631177

    there will be a script on showthread.php that essentially reads:

    PHP Code:
    $thread $_GET['t'];

    $sql='SELECT * FROM threads WHERE thread_id='$thread;

    // etc 

    Carrying non-sensitive data from one page to another
    data can be transferred via the URL from different scripts, allowing the data to be reused. Alternative to $_POST, $_SESSION etc

    url: edit_news.php?articleID=5&mode=1&preview=0

    these parameters can then be used to change how the script operates.

    PHP Code:
    // url = view.php?id=somevalue

    if(isset($_GET['id'])) {
      echo 
    'You are viewing ' $_GET['id']; //echos "You are viewing somevalue"
    } else {
      echo 
    'ID does not have a value!'//echos "ID does not have a value"


  6. #6
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    As a general rule of thumb, if the request changes something - e.g. adds, removes, deletes data in a database or writes to a file, or changes the user's logged in status, make it a post form.

    If it just displays data depending on a certain term/id, get is more suitable.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  7. #7
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Right, so gave a brilliant answer but to the wrong question, not the first time I've dont that.

    One place that GET comes in useful is when you want pretty urls, so sticking with the "use get when you want to GET some information" idea, your urls for your clothes store might look like this:

    site .com/article.php?garment=pants&color=purple

    But you want to make them look nice, and continue to have meaning, and be a bit seo friendlier:

    site .com/articles/pants/purple

    Then you'd have to go and read up on how to use Apache's mod_rewrite typically controlled from within .htaccess files - but other places too.

    If you want to know more about that, try this excellent resource.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •