mirror of
https://github.com/manualdousuario/marreta.git
synced 2025-09-01 18:20:22 +00:00
38 lines
940 B
PHP
38 lines
940 B
PHP
<?php
|
|
/**
|
|
* URL analysis utilities
|
|
* Checks status and redirects
|
|
*/
|
|
|
|
namespace Inc\URLAnalyzer;
|
|
|
|
use Curl\Curl;
|
|
|
|
class URLAnalyzerUtils extends URLAnalyzerBase
|
|
{
|
|
/** Gets URL status and redirect info */
|
|
public function checkStatus($url)
|
|
{
|
|
$curl = new Curl();
|
|
$curl->setFollowLocation();
|
|
$curl->setOpt(CURLOPT_TIMEOUT, 5);
|
|
$curl->setOpt(CURLOPT_SSL_VERIFYPEER, false);
|
|
$curl->setOpt(CURLOPT_NOBODY, true);
|
|
$curl->setUserAgent($this->getRandomUserAgent());
|
|
$curl->get($url);
|
|
|
|
if ($curl->error) {
|
|
return [
|
|
'finalUrl' => $url,
|
|
'hasRedirect' => false,
|
|
'httpCode' => $curl->httpStatusCode
|
|
];
|
|
}
|
|
|
|
return [
|
|
'finalUrl' => $curl->effectiveUrl,
|
|
'hasRedirect' => ($curl->effectiveUrl !== $url),
|
|
'httpCode' => $curl->httpStatusCode
|
|
];
|
|
}
|
|
}
|