F
F
felony13twelve2020-02-19 23:12:02
PHP
felony13twelve, 2020-02-19 23:12:02

How to allow access to php in ajax?

Moderators, correct me please

Hello again! I am interested in such a question, I can’t solve it.
There is such a site structure (this is an example, do not describe relatives)

/public_html
- php
-- reg.php
-- .htaccess
- index.php
- .htaccess


How can I make it so that if I write in the browser http://site.name/php/reg.phpso that it is not available to him, like, say, a 404 error, and if I write in ajax Then I need it to allow him access, how to do this? What code should be written in php folder in . htaccess url: "/php/reg.php"

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bkosun, 2020-02-19
@bkosun

There is no reliable way to determine that the request was made through Ajax, does not exist. You can use several different methods of verification, but such a system is easy to "bypass".

if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')
{    
    header("HTTP/1.0 404 Not Found");
    exit();    
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question