18 августа 2023
Нет комментариев
function days_to_birthdate($birthdate){ $bd=explode('.',$birthdate); $bd=mktime(0,0,0,$bd[1],$bd[0],date('Y')+($bd[1].$bd[0]<=date('md'))); return ceil(($bd-time())/86400); }
function days_to_birthdate($birthdate){ $bd=explode('.',$birthdate); $bd=mktime(0,0,0,$bd[1],$bd[0],date('Y')+($bd[1].$bd[0]<=date('md'))); return ceil(($bd-time())/86400); }
отправить тело запроса в get запросе используя curl
$timeout=5; $auth=array( 'WebApiSession: '.$WebApiSession, ); $curl=curl_init(); curl_setopt($curl,CURLOPT_CONNECTTIMEOUT,$timeout); curl_setopt($curl,CURLOPT_TIMEOUT,$timeout); curl_setopt($curl,CURLOPT_URL,$url); curl_setopt($curl,CURLOPT_HEADER,0); curl_setopt($curl,CURLOPT_RETURNTRANSFER,1); curl_setopt($curl,CURLOPT_HTTPHEADER,$auth); curl_setopt($curl,CURLOPT_CUSTOMREQUEST,'GET'); curl_setopt($curl,CURLOPT_POSTFIELDS,$booking_data); $result=curl_exec($curl);
if(str_ireplace($array,'',$str)!=$str){ echo 'found'; }
$mail->SMTPOptions=array( 'ssl'=>array( 'verify_peer'=>false, 'verify_peer_name'=>false, 'allow_self_signed'=>true ) );
$result=array(); ob_start('ob_gzhandler'); echo json_encode($result);
echo preg_replace('/<(\s*)img[^<>]*>/i','',$text);
В примере для PageSpeed Insights показываем вместо контента скриншот страницы
Вариант 1 через PageSpeed Insights API:
Ключ API получить здесь: https://developers.google.com/speed/docs/insights/v5/get-started
if(strpos($_SERVER['HTTP_USER_AGENT'],'Chrome-Lighthouse')!==false){ Define("IS_LIGHTHOUSE",1); } if(defined('IS_LIGHTHOUSE')){ $api_key="yourAPIKey"; $requested_link=explode('?',$_SERVER['REQUEST_URI']); $screen_url=$_SERVER['HTTP_X_FORWARDED_PROTO']."://".$_SERVER['HTTP_HOST'].$requested_link[0]; $strategy=(defined('IS_MOBILE'))?'MOBILE':'DESKTOP'; $curl_url="https://pagespeedonline.googleapis.com/pagespeedonline/v5/runPagespeed?url=".urlencode($screen_url)."&category=CATEGORY_UNSPECIFIED&strategy=".$strategy."&key=".$api_key; $curl=curl_init($curl_url); curl_setopt($curl,CURLOPT_RETURNTRANSFER,true); $response=curl_exec($curl); curl_close($curl); $googledata=json_decode($response,true); $screen_img=$googledata["lighthouseResult"]["audits"]["full-page-screenshot"]["details"]["screenshot"]["data"]; exit('<html><head><meta name="viewport" content="width=device-width,initial-scale=1"/></head><body><img src="'.$screen_img.'" alt="" width="100%" height="100%"/></body></html>'); }
Вариант 2 — более быстрый, не нужен ключ
if(strpos($_SERVER['HTTP_USER_AGENT'],'Chrome-Lighthouse')!==false){ Define("IS_LIGHTHOUSE",1); } if(defined('IS_LIGHTHOUSE')){ if(defined('IS_MOBILE')){ $w=375; $h=812; } else{ $w=1920; $h=1080; } $requested_link=explode('?',$_SERVER['REQUEST_URI']); $screen_url=$_SERVER['HTTP_X_FORWARDED_PROTO']."://".$_SERVER['HTTP_HOST'].$requested_link[0]; $screen_img="https://s0.wordpress.com/mshots/v1/".urlencode($screen_url)."?w=".$w."&h=".$h; exit('<html><head><meta name="viewport" content="width=device-width,initial-scale=1"/></head><body><img src="'.$screen_img.'" alt="" width="100%" height="100%"/></body></html>'); }
Спрятать адрес wordpress.com:
if(strpos($_SERVER['HTTP_USER_AGENT'],'Chrome-Lighthouse')!==false){ Define("IS_LIGHTHOUSE",1); } if(defined('IS_LIGHTHOUSE')){ if(defined('IS_MOBILE')){ $w=375; $h=812; } else{ $w=1920; $h=1080; } $requested_link=explode('?',$_SERVER['REQUEST_URI']); $screen_url=$_SERVER['HTTP_X_FORWARDED_PROTO']."://".$_SERVER['HTTP_HOST'].$requested_link[0]; $screen_img_url="https://s0.wordpress.com/mshots/v1/".urlencode($screen_url)."?w=".$w."&h=".$h; $curl=curl_init($screen_img_url); curl_setopt($curl,CURLOPT_RETURNTRANSFER,1); curl_setopt($curl,CURLOPT_FOLLOWLOCATION,true); curl_setopt($curl,CURLOPT_USERAGENT,'Mozilla/5.0 (Macintosh; Intel Mac OS X 12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36'); $img_data=curl_exec($curl); $screen_img='data:image/jpg;base64,'.base64_encode($img_data); exit('<html><head><meta name="viewport" content="width=device-width,initial-scale=1"/></head><body><img src="'.$screen_img.'" alt="" width="100%" height="100%"/></body></html>'); }