does $_SERVER['REQUEST_URI'] return the page it's programed in or the page that originated the call

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

  •  31-03-2022
  •  | 
  •  

Вопрос

i'm building a class which will house wrappers for the functions i most commonly use, one is a run query function which i will always call when i want to run a MySQL Query, inside it will clean up the query as to ensure there is no SQL Injection.

some thing this wrapper function will do is if it detects that the query is an attempt at SQL Injection it'll log the user IP, date and the query itself in a table so i can review later, some thing i was thinking about storing was $_SERVER['REQUEST_URI'] that way if it's a fault in one of my pages i can find the offending page and fix it.

however, something popped into my mind, does $_SERVER['REQUEST_URI'] return the page in which it was called on or not, the name of my class file is main.php

so i'm wondering, if i was to put $_SERVER['REQUEST_URI'] in my main.php file inside a function and then called that function in a test.php, which would it return, main or test

Это было полезно?

Решение

It's the URI, not necessarily an originating script. http://php.net/manual/en/reserved.variables.server.php

So it will depend on the url that was called in order to serve your script.

So for example, you could have htaccess rewrite the url so www.yoursite.com/something actually serves main.php which includes test.php. request URI would record /something and not any of the files that were used to serve the page.

You could just pass a unique ID to the wrapper method you created. You should be able to track and log which query was altered pretty easily assuming you write it out in a way that makes sense.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top