-2

Having an issue on our site. You can see more detailed info at http://www.themastfarminn.com/php-prob/

I sent in a support ticket to our hosting provider and here is what they replied:

|||||||||||||||||||||||||||

We recently updated our Mod Security settings for all signature accounts. This will block any requests that do not include the user-agent string in the HTTP header and send a forbidden response. To fix the problem you will need to update your script (curl script) to include a user-agent string and the server will then allow the connection.

|||||||||||||||||||||||||||

Do you know how I would go about updating our script (curl script) to include a user-agent string, as I have no idea what he means, and do not know what string, nor where, nor how to insert it.

Any help greatly appreciated.

Henri

1 Answers1

0

The CURLOPT_USERAGENT should be the browser name, version, etc... It can be set from the $_SERVER array, although there is nothing stopping you put whatever you wish in there. Ultimately, it is a(nother) config value that can be added as part of the cURL options if required.

// This is sort of pointless, but correct
$userAgent = 'Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0';

or

// This can't be trusted, but correct
$userAgent = $_SERVER['HTTP_USER_AGENT'];

or

// This is useless..  ..but not wrong
$userAgent = 'Whatever you feel like putting';

Then just add it to the list of options..

$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_USERAGENT, $userAgent );
curl_setopt( $ch, CURLOPT_HEADER, 0);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
etc...
MaggsWeb
  • 3,018
  • 1
  • 13
  • 23
  • Thanks Chris, in what file would I add: $ch = curl_init( $url ); curl_setopt( $ch, CURLOPT_USERAGENT, $userAgent ); curl_setopt( $ch, CURLOPT_HEADER, 0); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1); ? – Henri Deschamps Jul 06 '15 at 20:37
  • Whatever file you are already doing your cURL request in. Its sounds like you just need to add this additional config option to the existing list of options. – MaggsWeb Jul 06 '15 at 20:41
  • Thanks Chris, I think I am in over my head, I do not know where or how to add the strings above, and as far as I know I do not have access to curl file via FTP, don't know how the commands to access it via putty, nor know the command structure to add those strings. Basically I know how to edit PHP files via FTP. Is it complex and I need a programmer, or is this something I should be able to do? – Henri Deschamps Jul 06 '15 at 20:51
  • The cURL request will probably just be as above, in a normal PHP file. Download them all and search them for 'curl_init'. That's ya file. – MaggsWeb Jul 06 '15 at 20:59
  • I download every php file on my server, and did a search, nothing. I am on a shared hosting platform, and it must be in a directory above my access. I do have access to curl via putty just logged in and can see curl is installed on server but do not know what curl commands to execute to add <<$ch = curl_init( $url ); curl_setopt( $ch, CURLOPT_USERAGENT, $userAgent ); curl_setopt( $ch, CURLOPT_HEADER, 0); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1); >> to list of options. Will log in via Putty again and see if I can find it in help – Henri Deschamps Jul 06 '15 at 21:48
  • Would the proper command to issue via putty to curl be << curl -A $ch = curl_init( $url ); curl_setopt( $ch, CURLOPT_USERAGENT, $userAgent ); curl_setopt( $ch, CURLOPT_HEADER, 0); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1); >> – Henri Deschamps Jul 06 '15 at 22:06
  • or << curl -A --user-agent $ch = curl_init( $url ); curl_setopt( $ch, CURLOPT_USERAGENT, $userAgent ); curl_setopt( $ch, CURLOPT_HEADER, 0); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1); >> – Henri Deschamps Jul 06 '15 at 22:08
  • or << curl -A --user-agent $userAgent = $_SERVER['HTTP_USER_AGENT']; >> – Henri Deschamps Jul 06 '15 at 22:16