<?php
/**
* Redirect tester
* @note Drop leading slash from $urls
* e.g. $domain = 'http://website.com';
* e.g. $urls = ['/index.htm'];
*/
$domain = 'http://dev.local';
$urls = [
$domain . '/assets/placeholder-volcano__FocusFillWzE5MjAsOTIwLCJ5Iiw4MF0.jpg',
$domain . '/assets/readblocklogo.pdf',
];
function curlRequest( $url )
{
//format the xml to submit
$options = array(
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_ENCODING => "", // handle all encodings
CURLOPT_USERAGENT => "apache-redirect-tester", // who am i
CURLOPT_AUTOREFERER => true, // set referer on redirect
CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect
CURLOPT_TIMEOUT => 120, // timeout on response
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
CURLOPT_SSL_VERIFYHOST => false, // ignore the certificate matches the host.
CURLOPT_SSL_VERIFYPEER => false, // ignore validating the certificate against trusted CAs.
);
// Setup all the cURL shiznit.
$ch = curl_init( $url );
curl_setopt_array( $ch, $options );
$content = curl_exec( $ch );
$err = curl_errno( $ch );
$errmsg = curl_error( $ch );
$header = curl_getinfo( $ch );
curl_close( $ch );
// Bind all the response headers.
$header['errno'] = $err;
$header['errmsg'] = $errmsg;
$header['content'] = $content;
return $header;
}
foreach ($urls as $item)
{
$curlrequests = curlRequest($item);
// var_dump(array_keys($curlrequests));
if( php_sapi_name() == 'cli') {
echo $item .' : '. $curlrequests['url'] ."\n\r";
} else {
echo $item .' : '. $curlrequests['url'] .'<br>';
}
}