I am trying to write a simple PHP URL redirect script but it's not working.
<?php
if (isset($_GET['link'])) {
header('Location: $_GET['link']');
}else{
echo 'invalid link';
}
?>
If I access the script as http://www.example.com/redirect.php, then it goes into else loop and I get output as 'invalid link' in the browser.
But if I access it as https://www.example.com/redirect.php?link=https://www.google.com then I get HTTP error 500. Ideally page should be redirected to https://www.google.com
I am new to PHP and unable to figure it out, any help please?