Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在php中使用自定义url重定向_Php - Fatal编程技术网

如何在php中使用自定义url重定向

如何在php中使用自定义url重定向,php,Php,我需要编写一个php页面,用定制的查询字符串打开现有的url "http://existingurl?test=pass&newparam=".$_REQUEST['u']; 怎么做?像这样: <?php header('Location: http://existingurl?test=pass&newparam='.urlencode($_REQUEST['u'])); exit(); ?> 您只需使用header函数。 不要忘记使用urlencode来保

我需要编写一个php页面,用定制的查询字符串打开现有的url

"http://existingurl?test=pass&newparam=".$_REQUEST['u'];
怎么做?

像这样:

<?php

header('Location: http://existingurl?test=pass&newparam='.urlencode($_REQUEST['u']));
exit();

?>

您只需使用header函数。 不要忘记使用urlencode来保护来自$\u请求['u']的用户输入提交

<?php
    header('Location: http://existingurl?test=pass&newparam='.urlencode($_REQUEST['u']));
    exit();
?>
有关更多信息,下次您可以查看官方文档。


如果您的意思是需要从POST/GET请求中构建一个包含多个参数的查询字符串,那么您可能需要查看并将其附加到url中

您尝试了什么?你哪里有问题?PHP的头函数通常处理重定向。我们不需要在这里对$_请求['u']进行urlencode吗?@Valera-很好,编辑了我的答案。
header('Location: http://existingurl?test=pass&newparam='.urlencode($_REQUEST['u']));
die();