CURL on Apache showing .. "Access denied! Error 403"

I am testing a simple API using cURL. This is a call from (php file) one Apache server (php file) to another Apache server . It is normal to test locally. But when I test my network PCs, it shows the following 403 error:

Access forbidden! You don't have permission to access the requested object. It is either read-protected or not readable by the server. If you think this is a server error, please contact the webmaster. Error 403

Codes for Caller Server (Server 1):

 function apicall($request_url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $request_url); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $return = curl_exec($ch); curl_close($ch); return $return; } $request_url = 'http://192.168.1.205/api.php?cname=David'; $response = apicall($request_url); 


Codes for the response server (server 2):

 echo "Hello ".$_GET['cname']; 

cURL is enabled for both Apache. So why? What should I do?

0
source share
2 answers

It is not related to cURL, it is a problem with your Apache configuration.

Apache is configured in such a way that the resource with api.php unavailable for the machine on which your script is running.

In your Apache root directory configuration, you need to check these directives:

 # Yours will not look like this # The key point is look at the 'Order' and 'Allow'/'Deny' directives for the root directory Order allow,deny Allow from all 

See this and the sections below.

Alternatively, you might have some code somewhere in api.php that looks something like this:

 header('HTTP/1.1 403 Forbidden'); exit("Access forbidden!\nYou don't have permission to access the requested object. It is either read-protected or not readable by the server.\nIf you think this is a server error, please contact the webmaster.\nError 403"); 

... however, based on what you say in your code, I think this is about the Apache configuration.

+1
source

If you use WAMP, make sure you "host online" on the server.

Secondly,

Are you blocking his htaccess?

0
source

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


All Articles