]> _ Git - cubist_net.git/commitdiff
#7825
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 19 Nov 2025 14:53:45 +0000 (15:53 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 19 Nov 2025 14:53:45 +0000 (15:53 +0100)
composer.json
src/HTTP.php [new file with mode: 0644]

index 1f5116c0cd3668f0d40d2c17136caf6a4b68c665..54eb09405f0c6c4ffc67eabaaf9fda7729e45450 100644 (file)
@@ -22,7 +22,7 @@
         }
     ],
     "require": {
-        "php": ">=7.0.0",
+        "php": ">=7.4",
         "ext-ssh2": "*",
         "cubist/util": "dev-master",
         "ext-ftp": "*",
diff --git a/src/HTTP.php b/src/HTTP.php
new file mode 100644 (file)
index 0000000..4f31e15
--- /dev/null
@@ -0,0 +1,95 @@
+<?php
+
+namespace Cubist\Net;
+
+class HTTP
+{
+    /**
+     * @param string $url
+     * @param string|null $flaresolverr
+     * @return void
+     */
+    public static function getResponseCode(string $url, string $flaresolverr = null)
+    {
+
+    }
+
+    public static function getHttpCodeCloudflare($url) {
+        $apiUrl = 'http://flaresolverr:8191/v1';
+
+        $payload = json_encode([
+            'cmd' => 'request.get',
+            'url' => $url,
+            'maxTimeout' => 60000
+        ]);
+
+        /*$flaresolverrOptions = [
+            CURLOPT_POST => true,
+            CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
+            CURLOPT_POSTFIELDS => $payload,
+        ];*/
+
+        $ch = curl_init($apiUrl);
+        self::$curlOpt = [
+            CURLOPT_RETURNTRANSFER => true,
+            CURLOPT_HEADER         => true,
+            CURLOPT_NOBODY         => true,
+            CURLOPT_TIMEOUT        => self::$timeout,
+            CURLOPT_POST => true,
+            CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
+            CURLOPT_POSTFIELDS => $payload,
+        ];
+        curl_setopt_array($ch, self::$curlOpt);
+        $response = curl_exec($ch);
+
+        if(preg_match('/(error|code) \b(301|302|308|404|401|403|405|500|502|503)\b/', $response, $matches)) {
+            $httpcode = $matches[2] ?? '';
+            $finalUrl = '';
+            $finalHttpCode = '';
+        }
+
+        curl_close($ch);
+
+        return ['httpcode' => $httpcode, 'finalurl' => $finalUrl, 'finalHttpCode' => $finalHttpCode];
+    }
+
+    protected static function setCurlOpt($moreOptions = []) {
+        self::$curlOpt = [
+            CURLOPT_RETURNTRANSFER => true,
+            CURLOPT_HEADER         => true,
+            CURLOPT_NOBODY         => true,
+            CURLOPT_TIMEOUT        => self::$timeout,
+            ...$moreOptions
+        ];
+    }
+
+    public static function getUrlInfo($url) {
+        $headers = get_headers($url, 1);
+        if($headers['Server'] === "cloudflare") {
+            $response = self::getHttpCodeCloudflare($url);
+        }else {
+            $response = self::getHttpCode($url);
+        }
+        return $response;
+    }
+
+    public static function getHttpCodeComment($httpcode)
+    {
+        switch ($httpcode) {
+            case 301:
+                return " - Moved Permanently: the resource has a new permanent home — update your bookmarks or links.";
+            case 302:
+                return " - Found: tells the client to look at (browse to) another URL.";
+            //case 307:
+            //case 308:
+            case 400:
+                return " - Bad request: this and all future requests should be directed to the given URI.";
+        }
+    }
+
+    public static function youtubeVideoExist($videoID)
+    {
+        $headers = get_headers('https://www.youtube.com/oembed?format=json&url=http://www.youtube.com/watch?v=' . $videoID);
+        return (is_array($headers) && preg_match('/^HTTP\\/\\d+\\.\\d+\\s+2\\d\\d\\s+.*$/', $headers[0]));
+    }
+}