gpt4 book ai didi

php - 当参数之一是 url 时的 parse_url() 问题

转载 作者:可可西里 更新时间:2023-11-01 00:52:08 24 4
gpt4 key购买 nike

我调用了一个 php 脚本 http://site.com/process.php,它将 url 作为其参数之一。 for=

http://site.com/process.php?for=http://www.anotherwebsite.com

然后我这样做并尝试 parse_url() 但是 parse_url() 给出了一个解析错误。

$uri = $_SERVER['REQUEST_URI']; // /process.php?for=http://www.anotherwebsite.com
parse_url($uri);

如何在发送端(在 url 中)或在接收端(php)对 for 参数进行编码,以便 parse_url() 理解它是只是一个恰好看起来像 url 的参数?

最佳答案

在将您的 url 作为 get 参数包含之前,请使用 urlencode

$full_url = 'http://site.com/process.php?for=' . urlencode('http://www.anotherwebsite.com');

This function is convenient when encoding a string to be used in a query part of a URL, as a convenient way to pass variables to the next page.


要反转 urlencode 的结果,请使用 urldecode .正如马里奥在下面的评论中指出的那样,$_GET 参数已经进行了 url 解码。

关于php - 当参数之一是 url 时的 parse_url() 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4969058/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com