سؤال

I have a search function that calls a php-file ('live_search.php') via AJAX. So far so good.

There is an htaccess-file located in the same directory:

<FilesMatch "live_search.php">
Order Allow,Deny
Allow from xx.xx.xxx.xxx 127.0.0.1
Deny from all
</FilesMatch>

Note: xx.xx.xxx.xxx is the 'IP'-address of my domain (I don't want to post the actual IP-address).

When I use MAMP (or XAMPP) it works on my local machine. But on my host (online) AJAX is not able to get access to that file ('403 forbidden').

How do I get access to the file on my host via AJAX?

هل كانت مفيدة؟

المحلول

It works on your local machine because you have 127.0.0.1, which means if the request comes from the 127.0.0.1 IP (e.g. you are accessing it from your local machine) then allow the request. If you use that htaccess file on your host and you try to access the page, it's going to be your external IP, which isn't in the allow list, so you get a 403.

If you go to a service like this: http://www.whatismyip.com/ the IP address that they give you is going to be the one that is used to determine whether you can access the live_search.php file or not. And if the IP on that page isn't in the Allow list, you will get a 403. Anyone who tries to visit live_search.php who's IP isn't in your allow list will get a 403 result. Having the server's IP does absolutely nothing, except if someone has a browser open on the server and is browsing the page that makes the AJAX call.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top