What do u mean by Post and Get in PHP

Discussion in 'PHP' started by govind, Jan 4, 2010.

  1. #1
    Can anybody Please help me?
     
    govind, Jan 4, 2010 IP
  2. K.Meier

    K.Meier Well-Known Member

    Messages:
    281
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    110
    #2
    Those are methods in HTML for submitting forms.
    Google says:

     
    K.Meier, Jan 4, 2010 IP
  3. Bohra

    Bohra Prominent Member

    Messages:
    12,573
    Likes Received:
    537
    Best Answers:
    0
    Trophy Points:
    310
  4. vedicrishi

    vedicrishi Peon

    Messages:
    40
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    These are the form action method for submitting html or php forms.
    However, now GET method is also used for url rewriting.
    POST method is more secure and GET is fast.
     
    vedicrishi, Jan 4, 2010 IP
  5. BrettOwnz

    BrettOwnz Member

    Messages:
    286
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    28
    #5
    When writing a form in HTML, these are the two different methods for sending data to the PHP file that will process the form. When using a "POST" as the method in your form tag, the data will be sent to the PHP file as a POST variable. For example, here is a HTML file, form.html, which includes a simple form with one field. The form has been set to send the data using the "POST" method.

    Form.html:
    
    <html>
    <head>
    <title>Test Form</title>
    </head>
    <body>
    <form action="process.php" method="post">
    <label for="name">Name:</label><input type="text" name="name" />
    <input type="submit" name="submit" value="submit" />
    </form>
    </body>
    </html>
    
    HTML:
    We then have the PHP file, process.php which will receive the variables and retrieve them using the $_POST['varname'] method.

    Process.php:
    
    <?php
    
    if($_POST) {
         
    //Retrieve POST variables
    
    $name = $_POST["name"];
    
    //You would then do further PHP coding here to use that variable, for now i will just echo it
    
    echo $name;
    
    } else {
    
    echo "Post not received.";
    
    ?>
    
    PHP:
    That is a very simple code example of the PHP "POST" method. If you were to be using the "GET" method, your variables will be shown in the URL. For example, if we sent the same for using the "GET" method the URL would look like... http://www.yourwebsite.com/process.php?name=NAMEENTERED

    This method is not ideal for processing forms that have to do with logging in or any other type of personal information, as all of the information is revealed in the URL. In the case that you use the GET method, the only thing that will change in your code is here:

    
    $name = $_POST["name"];
    
    PHP:
    Would be:

    
    $name = $_GET["name"];
    
    PHP:
    I hope that helps explain the two different types and how to use them a little bit.

    -Brett
     
    BrettOwnz, Jan 6, 2010 IP
    luckymurari likes this.
  6. xenon2010

    xenon2010 Peon

    Messages:
    237
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Post used to store data and more secure..
    Get mostly used for URLs query.
    you cannot use POST to navigate and view this page http://www.sample.com/?name=asd
    GET is also used to create URLs and dynamic pages. its fast not secure most of hackers use GET variables to attack the website.
     
    xenon2010, Jan 7, 2010 IP
  7. Mail Propeller

    Mail Propeller Peon

    Messages:
    44
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    What makes post more secure?
     
    Mail Propeller, Jan 7, 2010 IP
  8. clox.c

    clox.c Peon

    Messages:
    30
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    when dealing with forms and also to transfer data from one page to another one, you basically need to use either a GET or POST request.

    GETs are explicit requests, so that when you load the other page the suer is able to see what the data is (i.e. whenever you see &, ?, = in the website URL there's been a GET request. You can access GET data with $_GET['id'] to get everything after id in the URL and so on

    POSTs are somewhat more reserved requests, as data is not visible by the user. When you reload a page and are asked to rePOST your data, there's been a POST sometime before you accessed that page.
    similarly to GETs, you access POST variables with $_POST['id']
     
    clox.c, Jan 7, 2010 IP
  9. Mail Propeller

    Mail Propeller Peon

    Messages:
    44
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #9
    GET and POST both transfer information to a URL.
    GET can be used at the end of a URL like example.php?user=MailPropeller&password=NoneOfYourBusiness
    They can both be used in <form> tags to by setting method="post" or method="get"
    If you want security use https.
     
    Mail Propeller, Jan 7, 2010 IP
  10. luckymurari

    luckymurari Active Member

    Messages:
    629
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    90
    #10
    I just came across this thread, and couldn't help but appreciate BrettOwnz for taking so much time in writing such a detailed post.
     
    luckymurari, Jan 7, 2010 IP
  11. xenon2010

    xenon2010 Peon

    Messages:
    237
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #11
    anyone can access GET variables from any simple browser. unlike POST you need to use special tool to access POST variables. like CURL..
    thats my opinion and thats how I see it..
     
    xenon2010, Jan 7, 2010 IP
  12. iAreCow

    iAreCow Peon

    Messages:
    85
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #12
    @xenon2010
    Couldn't agree, Curl is software that acts like a "real browser" in command-line scenario. LibCurl very well replaces real browser in server side scripting, allowing to GET/POST/use cookies/get cookies and so on.
    What's being POSTed can be seen from page's source code. To see what's really posted, use SmartSniff. To modify what's being posted, use FireBug under FireFox.
     
    iAreCow, Jan 7, 2010 IP
  13. BrettOwnz

    BrettOwnz Member

    Messages:
    286
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    28
    #13
    Thank you very much.

    I was more than happy to do so :)
     
    BrettOwnz, Jan 9, 2010 IP