36 lines
866 B
PHP
36 lines
866 B
PHP
<?php
|
|
declare(strict_types=1);
|
|
require_once __DIR__ . '/http-limits.php';
|
|
|
|
function scanOG(string $url): array {
|
|
$og = array();
|
|
$limits = httpLimits();
|
|
$ctx = stream_context_create([
|
|
'http' => [
|
|
'timeout' => $limits['timeout'],
|
|
'follow_location' => 1,
|
|
'max_redirects' => $limits['max_redirects'],
|
|
'user_agent' => $limits['user_agent'],
|
|
'ignore_errors' => true
|
|
],
|
|
'ssl' => [
|
|
'verify_peer' => true,
|
|
'verify_peer_name' => true
|
|
]
|
|
]);
|
|
$html = @file_get_contents($url, false, $ctx);
|
|
if ($html === false || strlen($html) > $limits['max_bytes']) {
|
|
return $og;
|
|
}
|
|
|
|
$re = '/<meta (name|property)=("|\')(.*?)("|\').*?content=("|\')(.*?)("|\')/m';
|
|
preg_match_all($re, $html, $matches, PREG_SET_ORDER, 0);
|
|
|
|
foreach($matches as $m) {
|
|
$og[$m[3]] = $m[6];
|
|
}
|
|
//print_r($og);
|
|
return $og;
|
|
}
|
|
?>
|