diff --git a/inc/class.php b/inc/class.php index 2560d19..e55b00e 100644 --- a/inc/class.php +++ b/inc/class.php @@ -8,13 +8,14 @@ class Follow const ERROR_CURL_REDIRECT = "Could not curl_getinfo the redirect URL"; // properties - public string $url; - public string $next; public int $code; public int $step; public bool $redirect; public array $path; public array $error; + public array $headers; + public string $url; + public string $next; // constructor public function __construct(string $url) @@ -25,10 +26,12 @@ class Follow $this->step = 1; $this->redirect = false; $this->error = []; + $this->headers = []; $this->path[$this->step] = [ 'step' => $this->step, 'url' => $this->url, 'code' => null, + 'headers' => [], 'next' => null ]; } @@ -45,7 +48,7 @@ class Follow } // update a path entry - public function updatePath(int $step, string $key, string $value): void + public function updatePath(int $step, string $key, $value): void { $this->path[$step][$key] = $value; } @@ -60,7 +63,7 @@ class Follow return false; } - // set request headers and execute + // set request header options $response = curl_setopt($ch, CURLOPT_URL, $this->url); $response = curl_setopt($ch, CURLOPT_HEADER, true); // enable this for debugging $response = curl_setopt($ch, CURLOPT_HTTPGET, true); // redundant but making sure it's a GET @@ -69,6 +72,31 @@ class Follow $response = curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return output instead of going to screen $response = curl_setopt($ch, CURLOPT_TIMEOUT, 60); $response = curl_setopt($ch, CURLOPT_USERAGENT, self::USER_AGENT); + + // save response header to $header variable + $headers = []; + curl_setopt( + $ch, + CURLOPT_HEADERFUNCTION, + function($curl, $header) use (&$headers) + { + $len = strlen($header); + $header = explode(':', $header, 2); + + // ignore invalid headers + if (count($header) < 2) { + return $len; + } + + // save the header formatted + $headers[strtolower(trim($header[0]))][] = trim($header[1]); + + // return the header length + return $len; + } + ); + + // execute the curl handle $response = curl_exec($ch); // check for a response @@ -79,6 +107,10 @@ class Follow } else { + // save the response headers to the path entry + $this->headers = $headers; + $this->updatePath($this->step, 'headers', $headers); + // get the http status code if (curl_getinfo($ch, CURLINFO_HTTP_CODE)) { @@ -132,6 +164,7 @@ class Follow 'step' => $this->step, 'url' => $this->next, 'code' => null, + 'header' => '', 'next' => null ]); diff --git a/inc/search.php b/inc/search.php index 2b76de8..3faa96c 100644 --- a/inc/search.php +++ b/inc/search.php @@ -34,7 +34,7 @@ if (isset($_POST['url'])) // update our code $code = ($request->code) ? $request->code : false; - } while (substr($code, 0, 1) != 2); + } while (substr($code, 0, 1) == 3); // continue while we have a 3XX code } else { diff --git a/inc/style.css b/inc/style.css index 38904c2..627a3cd 100644 --- a/inc/style.css +++ b/inc/style.css @@ -47,9 +47,20 @@ a:hover { color: #000; text-decoration-color: #000; } +nav { + align-items: center; + display: flex; + gap: 1.5rem; +} nav a { - font-size: 1.1rem; - line-height: 1.6rem; + align-items: center; + display: inline-flex; + font-size: 1.1rem; + line-height: 1.6rem; +} +nav svg { + height: 1.5rem; + width: 1.5rem; } h1 { @@ -208,7 +219,7 @@ details[open] + details { } code { - font-family: Menlo, monospace; + font-family: Menlo, 'Berkeley Mono', Hack, monospace; font-size: 0.9rem; background: #fff; padding: 0.1rem 0.2rem; @@ -255,6 +266,12 @@ th { text-transform: uppercase; text-align: left; } +th:first-child { + padding-left: 3rem; +} +tr { + position: relative; +} td { background-color: #fafafa; border-bottom: 1px solid #1a1a1a; @@ -263,17 +280,20 @@ td { word-wrap: anywhere; } td:first-child { - text-align: center; + width: 0; } td:nth-child(2) { + text-align: center; +} +td:nth-child(3) { line-height: 1.5rem; padding: 0.8rem 1rem; width: 100%; } -td:nth-child(2) a:hover { +td:nth-child(3) a:hover { text-decoration-color: transparent; } -td:nth-child(4) { +td:nth-child(5) { text-align: center; padding-right: 1.5rem; } @@ -293,11 +313,11 @@ td b i { display: inline-block; transition: transform 150ms ease-in-out; } -td:nth-child(2) a:hover b { +td:nth-child(3) a:hover b { border-color: #1a1a1a; color: #1a1a1a; } -td:nth-child(2) a:hover b i { +td:nth-child(3) a:hover b i { transform: rotate(45deg); } tbody tr:nth-child(odd) td { @@ -307,6 +327,59 @@ tbody td:last-child { padding-left: 0; width: 1rem; } +td label { + cursor: pointer; + left: 1.25rem; + position: absolute; + top: 0.85rem; + transition: transform 150ms ease-in-out; +} +td label i { + font-size: 1.25rem; + font-style: normal; + line-height: 1rem; +} +section { + display: flex; + max-height: 0; + overflow: hidden; + flex-direction: column; + transition: max-height 200ms ease; +} +hgroup { + display: flex; + flex-direction: column; + + margin-bottom: 0.5rem; +} +section hgroup:first-of-type { + padding-top: 1rem; +} +td input[type="checkbox"] { + display: none; +} +td input[type="checkbox"]:checked + section { + max-height: 100rem; +} +td input[type="checkbox"]:checked + section > label { + transform: rotate(90deg); +} +q { + color: #666; + font-size: 0.8rem; + font-weight: bold; + text-transform: uppercase; + white-space: nowrap; +} +q::before, +q::after { + content: ''; +} +mark { + background: none; + font-family: Menlo, 'Berkeley Mono', Hack, monospace; + font-size: 0.9rem; +} caption { caption-side: bottom; line-height: 1.5rem; diff --git a/index.php b/index.php index 6562cde..f408b6e 100644 --- a/index.php +++ b/index.php @@ -16,10 +16,20 @@ include('inc/codes.php');

Follow URL Redirect Checker

- +
@@ -55,7 +65,7 @@ if (isset($request) && count($request->path) > 0) - + @@ -63,14 +73,35 @@ if (isset($request) && count($request->path) > 0) "; foreach ($request->path as $step) { - $item = $step['step']; - $url = $step['url']; - $code = $step['code']; - $next = ($step['next']) ? '↩︎' : ((isset($error)) ? 'x' : '✓'); - echo " + $item = $step['step']; + $url = $step['url']; + $code = $step['code']; + $headers = $step['headers']; + $next = ($step['next']) ? '↩︎' : ((isset($error)) ? 'x' : '✓'); + echo " - - + + + ";
StepStep Request Code
".$item."".$url." ↗︎ ".$item." +
".$url." ↗︎
"; + if (is_array($headers) && count($headers) > 0) + { + echo " + +
+ "; + foreach ($headers as $hkey => $hval) + { + echo " +
+ ".$hkey."".$hval[0]." +
"; + } + echo " +
"; + } + echo " +
".$code." ".$next."