There is a page.php file with live chat on Ajax, which accesses another ajaxPost.php file using code:

$("#userArea").submit(function(){ $.post('/ajaxPost', $('#userArea').serialize(), function(data){ $("#messages").append('<div>'+data+'</div>'); }); 

If in ajaxPost.php enter the code:

 echo $_SERVER[REQUEST_URI]; 

Then the word "ajaxPost" (file name) is displayed. The question is how to display the REQUEST_URI file from which the request came, in this case, from page.php?

  • one
    $_SERVER['HTTP_REFERER'] ? - Roman Paradeev
  • @ Roman Paradeev hugged you, man. - Bim Bam

1 answer 1

 echo $_SERVER['HTTP_REFERER']; 

From the documentation :

The address of the page (if any) This is set by the user agent. Not all user agents will set this ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.

It should be borne in mind that the Referer header does not guarantee that the request was executed from a specific page.

Therefore, it cannot be used, for example, in order to limit access.