Reputation: 487
I've got a few URL's that are being run through php curl so that I can get the HTTP Code. The funny thing is, some URL's work fine and return 200, but others always return 400. The problem only exist when I feed the URL from the database, if I run it by hardcoding it then it returns 200 as it should.
I've tried urlencoding/decoding and it's not the issue. It looks fine in appearances. The one odd thing that I've been able to find is that the 400 URL's always have a [content_type] => text/html; charset=iso-8859-1
. The url's are also really simple https://sometext.something.something/test
and don't have any parameters
Here's the PHP code i've been running the URL through. It works on my localhost just fine, but on the server it causes issues.
function checkStatus($url) {
$urlencode=urlencode($url);
foreach (explode('&', $urlencode) as $chunk) {
$param = explode("=", $chunk);
if ($param) {
echo urldecode($param[0]);
$ch = curl_init(urldecode($param[0]));
}
}
//$ch = curl_init($urlencode);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
// curl_setopt($ch, CURLOPT_TIMEOUT, 10);
// curl_setopt($ch, CURLINFO_CONTENT_TYPE, true);
// curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:text/html;charset=UTF-8'));
curl_exec($ch);
$returnCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error_report= curl_getinfo($ch);
print_r($error_report);
curl_close($ch);
return $returnCode;
}
Here's a sample of the error message:
Array
(
[url] => https://url.net/something
[content_type] => text/html; charset=iso-8859-1
[http_code] => 400
[header_size] => 171
[request_size] => 83
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.056926
[namelookup_time] => 0.003457
[connect_time] => 0.004276
[pretransfer_time] => 0.01614
[size_upload] => 0
[size_download] => 0
[speed_download] => 0
[speed_upload] => 0
[download_content_length] => -1
[upload_content_length] => 0
[starttransfer_time] => 0.056906
[redirect_time] => 0
[certinfo] => Array
(
)
)
Upvotes: 0
Views: 2450
Reputation: 39355
Your URL has https://
that's why it doesn't work for you.
If the data security is not a problem for you, then you can use the following option to use insecure communication for ssl.
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
Upvotes: 1