0
votes

I have an ASP.NET Website and hosted on shared hosting and everything is working fine but recently I had requirement to call one page of website from php script via cURL but while executing php script via php-cgi.exe I am getting below error;

HTTP Error 403.0 - ModSecurity Action You do not have permission to view this directory or page.

Note I am able to browse that page from my browser without login to website.

What can be the possible cause for this error and could someone guide me to resolve this issue?

PHP Script

<?php
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, "http://<domainname>//<filename>.aspx");
    curl_exec($curl);
    curl_close($curl);
?>

Thanks in advance!

1
Your URL should be wrong, for what thre response states the URL is pointing to a directory, not a file.Gusman
@Gusman I cross checked URL it is the same URL which I used in browser. I cannot share exact URL but "domainname/filename.aspx" is url which I accessed in browser and used in php script.Jignesh Thakker
Hmmm, is the protocol the same (http vs https)? I've found some cases where misconfigured servers respond differently depending on the protocol. Else check any difference for subtle it seems, there must be the problem (different method (get, post, put)?, any difference on domain name?).Gusman
@Gusman Protocol is http in both case browser and php script. I got the problem I haven't set user agent in cURL request. After setting user agent everything is working properly. Thanks for your help.Jignesh Thakker

1 Answers

0
votes

After Analyzing issue found that error was coming due to user agent was not set in cURL request.

Updated PHP script;

<?php
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, "http://<domainname>//<filename>.aspx");
    curl_setopt($curl,CURLOPT_USERAGENT,"useragentvalue");
    curl_exec($curl);
    curl_close($curl);
?>