首页 > 解决方案 > 如何从php上的GET变量回显javascript编码的url

问题描述

如何从 php 上的 GET 方法回显解码的 url,

我有这个链接:

localhost/whatsapp?text=Hello%2C%20Who%20are%20U%3F%0AName%3A%20%0AAddress%3A%20%0AAge%3A%20

使用此代码

$text = $_GET['text'];
header("Location: https://web.whatsapp.com/send?phone=00000000&text=".$text);

但得到错误

警告:标头可能不包含多个标头,在 index.php 中检测到新行在线

标签: php

解决方案


当您从中检索值时$_GET,它们会被URL 解码。如果你想把它传回去,你需要再次编码,这样换行符、空格和其他奇怪的字符就会被编码。用于urlencode($text)此。

$text = $_GET['text'];
header("Location: https://web.whatsapp.com/send?phone=00000000&text=".urlencode($text));

推荐阅读