Adds new _GET variable to automatically go to the end URL; cleans up search.php to be tidier; allows both GET and POST urls
This commit is contained in:
		
							parent
							
								
									0c551aadd5
								
							
						
					
					
						commit
						516a1f59bc
					
				@ -159,14 +159,14 @@ class Follow
 | 
				
			|||||||
            // start the next path
 | 
					            // start the next path
 | 
				
			||||||
            $this->step++;
 | 
					            $this->step++;
 | 
				
			||||||
            $this->addPath(
 | 
					            $this->addPath(
 | 
				
			||||||
              $this->step,
 | 
					                $this->step,
 | 
				
			||||||
              [
 | 
					                [
 | 
				
			||||||
                'step' => $this->step,
 | 
					                    'step' => $this->step,
 | 
				
			||||||
                'url' => $this->next,
 | 
					                    'url' => $this->next,
 | 
				
			||||||
                'code' => null,
 | 
					                    'code' => null,
 | 
				
			||||||
                'header' => '',
 | 
					                    'header' => '',
 | 
				
			||||||
                'next' => null
 | 
					                    'next' => null
 | 
				
			||||||
              ]);
 | 
					                ]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            return true;
 | 
					            return true;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
				
			|||||||
@ -1,19 +1,26 @@
 | 
				
			|||||||
<?php
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// handle form submissions
 | 
					// handle form submissions
 | 
				
			||||||
if (isset($_POST['url']))
 | 
					if (isset($_POST['url']) || isset($_GET['url']))
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					    // get the correct url
 | 
				
			||||||
 | 
					    $url = $_POST['url'] ?? $_GET['url'];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // check that we got a valid URL
 | 
					    // check that we got a valid URL
 | 
				
			||||||
    $url = (filter_var(trim($_POST['url']), FILTER_VALIDATE_URL))
 | 
					    $url = (filter_var(trim($url, FILTER_VALIDATE_URL)))
 | 
				
			||||||
         ? trim($_POST['url'])
 | 
					         ? trim($url)
 | 
				
			||||||
         : false;
 | 
					         : false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // if so, start up the redirect checks
 | 
					    // if so, start up the redirect checks
 | 
				
			||||||
    if ($url)
 | 
					    if ($url)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        // make a request for this url and add to the path
 | 
					        // make a request for this url and add to the path, and make sure we don't go too long
 | 
				
			||||||
        $request = new Follow($url);
 | 
					        $request = new Follow($url);
 | 
				
			||||||
        $code = '';
 | 
					        $code = '';
 | 
				
			||||||
 | 
					        $hops = 0;
 | 
				
			||||||
 | 
					        $max = 10;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // keep making more requests until we get a 3XX
 | 
				
			||||||
        do {
 | 
					        do {
 | 
				
			||||||
            // set the URL
 | 
					            // set the URL
 | 
				
			||||||
            $request->url = $url;
 | 
					            $request->url = $url;
 | 
				
			||||||
@ -29,12 +36,22 @@ if (isset($_POST['url']))
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // if we have a redirect to follow, update our working $url
 | 
					            // if we have a redirect to follow, update our working $url
 | 
				
			||||||
            $url = ($request->next) ? $request->next : false;
 | 
					            $url = $request->next ?? false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // update our code
 | 
					            // update our code
 | 
				
			||||||
            $code = ($request->code) ? $request->code : false;
 | 
					            $code = $request->code ?? false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        } while (substr($code, 0, 1) == 3); // continue while we have a 3XX code
 | 
					            // increment our number of requests
 | 
				
			||||||
 | 
					            $hops++;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        } while ($hops < $max && $code && substr((string) $code, 0, 1) === '3'); // continue while we have a 3XX code
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // if we got a GET to automatically redirect to the url, do that now
 | 
				
			||||||
 | 
					        if (isset($_GET['go']) && $url)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            header("Location: ".$url);
 | 
				
			||||||
 | 
					            exit;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user