douwen5951 2014-08-22 11:58
浏览 31

将“标题('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);
 ?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 测距传感器数据手册i2c
    • ¥15 RPA正常跑,cmd输入cookies跑不出来
    • ¥15 求帮我调试一下freefem代码
    • ¥15 matlab代码解决,怎么运行
    • ¥15 R语言Rstudio突然无法启动
    • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
    • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
    • ¥15 用windows做服务的同志有吗
    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法