When a user access a directory directly, Is a GET request sent by default?

StackOverflow https://stackoverflow.com/questions/22842582

  •  27-06-2023
  •  | 
  •  

Pergunta

I have a page with this code:

<?php
    if ($_SERVER['REQUEST_METHOD'] !== 'GET') {
    header('HTTP/1.0 405 Method Not Allowed');
    exit(); }

If I access it with a form in GET method, it works, and doesn't exit, which is ok. But when I try to access this file directly, I would expect the file to perform the exit -
unless, a GET request is sent automatically whenever one access a file, even when not through a form?

Foi útil?

Solução

unless, a GET request is sent automatically whenever one access a file, even when not through a form?

It is.

When you follow a link or type a URL into the address bar, you are getting a resource (you aren't asking for just metadata (HEAD), or sending any kind of data (PUT, POST), or deleting something (DELETE)) so you use GET.

Outras dicas

Unless you specifically issue a POST, PUT, HEAD, etc. request then it is GET. If you click a link in a page or use the URL bar in the browser it is GET.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top