]> _ Git - psq.git/commitdiff
Update GetPageTitleFromUrl.php
authorLouis Jeckel <louis.jeckel@outlook.cm>
Thu, 27 Aug 2020 17:32:25 +0000 (19:32 +0200)
committerLouis Jeckel <louis.jeckel@outlook.cm>
Thu, 27 Aug 2020 17:32:25 +0000 (19:32 +0200)
app/Invokables/GetPageTitleFromUrl.php

index bf38881b7b1c8d41bc92f7e0b6646141434c5b4b..4b1698d3afc72a712dcac601224f52d10955aef0 100644 (file)
@@ -9,15 +9,40 @@ class GetPageTitleFromUrl
     public function __invoke($url): string
     {
 
+
+        $ch = curl_init();
+        curl_setopt($ch, CURLOPT_URL, $url);
+
+
+
+        $headers = [];
+        $headers[] = "User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:50.0) Gecko/20100101 Firefox/50.0";
+        $headers[] = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
+        $headers[] = "Accept-Language: en-US,en;q=0.5";
+        $headers[] = "Accept-Encoding: gzip, deflate, br";
+
+        curl_setopt($ch,CURLOPT_ENCODING , "gzip");
+
+        curl_setopt($ch, CURLOPT_HTTPHEADER , $headers);
+
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+
+        $str = curl_exec($ch);
+
+        curl_close($ch);
+
+
         $context = stream_context_create(
             [
                 "http" => [
-                    "header" => "User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36"
+//                    "header" => implode("\r\n", $headers),
+                    "header" => "User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36",
+
                 ]
             ]
         );
 
-        $str = file_get_contents($url, false, $context);
+//        $str = file_get_contents($url, false, $context);
         if($str !== ''){
             $str = trim(preg_replace('/\s+/', ' ', $str)); // supports line breaks inside <title>
             preg_match("/<title>(.*)<\/title>/i",$str,$title); // ignore case