How does 'post' and 'get' work?

Discussion in 'PHP' started by IamNed, Jul 22, 2006.

  1. #1
    I see these PHP sripts that automate taskts use something called 'post' and 'get' and sometimes a 'text file' as well. How does all of this work?

    For example, there isa pHP script that generates myspace bulletins and it uses 'get' and 'post' funtions and a .txt file.
     
    IamNed, Jul 22, 2006 IP
  2. coderlinks

    coderlinks Peon

    Messages:
    282
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hi,
    You need to read up on how the internet works.

    You see, websites are served on the internet through a protocol called HTTP. When we type in a URL in our browser, it sends a GET request to the server. Like for example, if we access, www.coderlinks.com/index.php, the browser sends a request

    GET /index.php HTTP/1.1
    Host: coderlinks.com

    You can also send data through get like this:
    Basically its asking the server to give the index.php file. The HTTP/1.1 part indicates the HTTP Protocol version.

    GET /index.php?p=d
    Host: coderlinks.com

    Here also the same file is fetched except that the file gets a variable named p with the value 'd' . One place you see this is in HTML forms, like the ones that ask you to subscribe to a mailing list and all. The default method used in forms in GET. So when you type in the email and click submit, you are in effect visiting the address:

    http://www.blahbla.com/mailing.php?name=Your_Name&email=Your_email

    the two different data are separated by an '&' symbol. POST is another way of sending data. Here instead of putting the data in the URL, it is put in the request itself, so that the URL looks clean. Like this:

    POST mailform.php HTTP/1.1
    Host: coderlinks.com
    Content-type: application/x-www-form-urlencoded
    Content-length: 31

    name=Your_Name&email=Your_email

    And text file is just that, a text file :D . I dont know what are myspace bulletins as I dont use MySpace. But maybe, they just use GET to get some data from an internet page and store this info in text files. This data is later taken from the text file show the data.

    If you didn't understand all that, I suggest you read up on the working of the internet and HTTP. I will give you some useful resoruces:

    http://www.wdvl.com/Internet/Protocols/HTTP/Request.html
    http://en.wikipedia.org/wiki/Internet#Internet_protocols
    http://en.wikipedia.org/wiki/HTTP

    Thomas
     
    coderlinks, Jul 23, 2006 IP
  3. IamNed

    IamNed Peon

    Messages:
    2,707
    Likes Received:
    276
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for the detailed responce.
     
    IamNed, Jul 23, 2006 IP
  4. coderlinks

    coderlinks Peon

    Messages:
    282
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    0
    #4
    No probs :)
     
    coderlinks, Jul 23, 2006 IP
  5. daboss

    daboss Guest

    Messages:
    2,249
    Likes Received:
    151
    Best Answers:
    0
    Trophy Points:
    0
    #5
    i'll try to answer that in simpler terms...

    e.g. you can specify a php page as the 'action' of a form... and when the user click on the submit button on the form, the values of the individual fields of the form gets passed over to the php page specified through the use of $_POST['field_name']

    e.g. in the url, you sometimes see ?variable=value... e.g. http://www.mydomain.com/page.php?var=hello - in the php code of page.php, you can read what was passed in through the ?var=hello part as $_GET['var']...

    hopefully the above made it a little simpler...
     
    daboss, Jul 23, 2006 IP