I am looking for a way to return a twig view, wait 5 seconds and then send the user to an external URL.
When I visit the URL, I only see a white page as the template doesn't get an opportunity to load.
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class RedirectController extends AbstractController
{
public function index(Request $request)
{
// TO DO - check if url is valid
$url = $request->get('url');
$this->redirectAway($url);
return $this->render('base/redirect.html.twig', ['url' => $url]);
}
public function redirectAway($url)
{
$response = new Response();
$response->setStatusCode(200);
$response->headers->set('Refresh', '5; url=https://' . $url);
$response->send();
return $response;
}
}
Any help would be most appreciated! <3 I am trying to implement a redirect notice for users for external URLs.