SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2007
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Request Method for a Search Form

    I have an 'Advance Search' form which the users can fill out and submit. However the form has a lot of fields. Do I risk outgrowing any URL length limits if I use GET method to submit the query. Is it ok to use 'POST' request method for search queries?

  2. #2
    SitePoint Addict
    Join Date
    Dec 2007
    Posts
    358
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    http://httpd.apache.org/docs/2.2/mod...mitrequestline

    Request line is limited to 8190 bytes by default.

    I think that practically accepted GET request line is up to 1024 bytes. If it can be longer, you can save the parameters in the database/session and only pass search id between pages.
    I'm creating trouble-free Apache, PHP, MySQL installer, WITSuite,
    and use it to setup my development environment.
    Demo, support, contact. Questions?

  3. #3
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's a very bad idea to use POST for a search. GET is for requests that don't change state. POST is for requests that do change state. Are you absolutely certain that you can't slim down the amount of information you're sending as input to the query? (For example, only send input that differs from default).
    Last edited by kyberfabrikken; Apr 12, 2009 at 06:42. Reason: Rather confusing typo .. I replaced POST with GET, thereby completely negating the meaning of what I tried to say.

  4. #4
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kyberfabrikken View Post
    It's a very bad idea to use GET for a search. GET is for requests that don't change state. POST is for requests that do change state. Are you absolutely certain that you can't slim down the amount of information you're sending as input to the query? (For example, only send input that differs from default).
    always learning something new

  5. #5
    SitePoint Enthusiast
    Join Date
    Apr 2007
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kyberfabrikken View Post
    It's a very bad idea to use GET for a search. GET is for requests that don't change state. POST is for requests that do change state. Are you absolutely certain that you can't slim down the amount of information you're sending as input to the query? (For example, only send input that differs from default).
    1. Isn't typical search an idempotent operation?
    2 . doesn't Google uses 'GET' for search? Is Google doing it wrong?
    3. How do we get around the issue of 'lost bookmark-ability' resulting from the use of 'POST'.

  6. #6
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Java987 View Post
    always learning something new
    Whoops. I screwed up in my posting; In the first sentence, I should have written POST, but accidentally wrote GET, thereby completely negating the meaning. I've corrected it now - Sorry for the confusion.

  7. #7
    PHP/Rails Developer Czaries's Avatar
    Join Date
    May 2004
    Location
    Central USA
    Posts
    806
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Always use GET for searching. POST requests are for changing state. Searching is not changing the state of any records, just pulling them up for viewing. Besides, using the back button after POST requests is a pain.

  8. #8
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why not use both? Something like this, with GET being the primary place to get the data from:

    PHP Code:
    $search = (isset($_GET['search'])) ? $_GET['search'] : @$_POST['search']; 

  9. #9
    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)
    I think the OP was thinking more about the sending than the receiving of the form
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona


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
  •