PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, February 15, 2022

[FIXED] Can't access file via AJAX on host

 February 15, 2022     .htaccess, ajax, http-status-code-403, localhost, mamp     No comments   

Issue

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?


Solution

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.



Answered By - Jon Lin
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing