将“标题('Location:$ variable')导出到文件的服务器要求

I have recently started learning php, and I'm fiddling around with a redirect script. However, it is not working as intended on the server I'm supposed to use. I have tested it on 3 other servers, one being from the same provider (vps.net), and it works on all the other 3.

PHP versions tested: 5.4.31, 5.4.30(This is the one that's not working), 5.3.20, 5.2.17.

Are there any spesific server requirements for making this code work?

The issue seems to be the exporting of the $url to the Header('Location: $url'). In url1.php, the code misses the data from the variable, giving this result:

<?php  header( 'Location: ' ) ;  ?>

Whereas another server will have url1.php like this:

<?php  header( 'Location: http://facebook.com' ) ;  ?>

What kind of server settings is required for it to work, or are there any simple code tweaks that can make it more universal?

Here's the code:

<form method="post" action="index.php">
    <label for="link1" value="Link 1"><input type="text" name="link1" id="link1">
    <label for="link2" value="Link 2"><input type="text" name="link2" id="link2">
    <input type="submit" value="Split it!">
 </form>

 <?php
 $url1 = $_POST["link1"];
 $url2 = $_POST["link2"];

 echo "Your first url: <b>" . $url1 . "</b><br>" ;
 echo "Your second url: <b>" . $url2 . "</b>" ;

$var_str = var_export($url1, true);
$var = "<?php  header( 'Location: $url1' ) ;  ?>";
file_put_contents('url1.php', $var);

$var_str = var_export($url2, true);
$var = "<?php  header( 'Location: $url2' ) ;  ?>";
file_put_contents('url2.php', $var);
 ?>