How to check the address the page is accessing?

I was wondering if it is possible to grab the URL from which the page was accessed? For example, let's say if I have an index.php file. Access to it is possible from almost anywhere, depending on where I placed it. For instance:

 - http://folder1/index.php
 - http://nicefolder1/index.php

Anyway, can I find out where the page was available from? I would like to parse this url, and if it were from nicefolder1, I would like to do something like echo "That was a good location to be executed from": D! Just what I was interested in ...

+3
source share
3 answers

$ _ SERVER ['PHP_SELF']

Must have the correct URL.

Additional Information

+5
source

$_ SERVER php.net, $_SERVER ['PHP_SELF'] .

0

, , :

$_SERVER['HTTP_HOST']contains the host name and the $_SERVER['REQUEST_URI']absolute path to the requested resource. These two, combined with the schema prefix, give you the full URL:

$url = 'http://'. $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
0
source

Source: https://habr.com/ru/post/1779422/


All Articles