Should GET requests store to database?

April 15, 2019, at 06:50 AM

I’ve read that you should not use GET requests if you are modifying the database. How would you record analytics about your website then?

For example, I want to record page views whenever someone visits a page. I would need to update views = views + 1 in the database. Is this OK, despite using a GET request, or is there another technique? Surely, not every request should be a POST request.

Answer 1

The general advice about how to use POST vs. GET shows up in RFC 1945 from 23 years ago:

The GET method means retrieve whatever information (in the form of an entity) is identified by the Request-URI.


POST is designed to allow a uniform method to cover the following functions:

  • Annotation of existing resources;
  • Posting a message to a bulletin board, newsgroup, mailing list, or similar group of articles;
  • Providing a block of data, such as the result of submitting a form [3], to a data-handling process;
  • Extending a database through an append operation.

These guidelines remain in effect to this day, but they cover the primary purpose of the user's page request.

The act of incrementing a view counter is incidental to the primary purpose of the request, which is to view the page content. Indeed, the user is likely unaware that this database is occurring.

(Of course, you must expect that you will receive duplicates as users move through browser history, caches are populated, or spiders crawl your pages. This wouldn't be the case if a POST request was made.)

Answer 2

It's ok.

When you make POST request, you actually wait for POST params to come and you build your database insert query based on parameters which you've got from browser. On GET request you actually implement your own business logic, so user won't ever know what is going on the side.

And for the finish, actually sometimes you can do something, what's going against rules, rules are good, but we are able not to follow them, that's what makes us human, if we would strictly follow all the rules, it would be cumbersome.

Rent Charter Buses Company
How to Integrate wordpress auction plugin with realestate theme

How to Integrate wordpress auction plugin with realestate theme

I want to integrate a wordpress auction plugin into my realestate themeI want the auction option to appear when a product is posted as a property

count must be an array or object [on hold]

count must be an array or object [on hold]

I just started learning laravel and I created a new blade called indexblade inside views/posts folder and inside it, I used @if(count($posts)>0) statement to show posts, however, it is showing:

form is uploading to /tmp/phpHQ6U5X instead of newly set /var/www/html/upload_tmp

form is uploading to /tmp/phpHQ6U5X instead of newly set /var/www/html/upload_tmp

I am trying to upload files to my server through a CRUDI am having an issue moving the uploaded file to its new directory which exists