gpt4 book ai didi

php - $_SERVER ['REQUEST_URI' ] 和 $_GET

转载 作者:行者123 更新时间:2023-12-05 00:21:05 25 4
gpt4 key购买 nike

如何在包含上一页的其他变量的 URL 中传递目标变量?

基本上,当我在 index.php?year=2014&month=3 上并且单击 edit.php 链接时,我希望它记住 (index.php?year= 2014&month=3) 所以它在编辑后让我回到那里...我把它放在 $destination 但它与我的 URL 变量冲突...

SERVER['REQUEST_URI'] 返回:index.php?year=2014&month=3

我的 php 代码:

$destination = $_SERVER['REQUEST_URI'];
$edit_url = "edit.php?id=$id&proj=$proj&t=$t&year=$year&month=$month&day=$day&destination=$destination";

当我点击编辑链接时:http://www.site.com/edit.php?id=5&proj=3&t=1&year=2014&month=4&day=13&destination=/index.php?year=2014&month=3

当我进入 edit.php 时,我注意到它没有捕获隐藏的输入 &month=3在源代码中显示:

<input type="hidden" name="destination" value="/index.php?year=2014">

它应该显示:

<input type="hidden" name="destination" value="/index.php?year=2014&month=3">

我知道这是因为 & 符号导致的...是否可以制作 url.php?blah=1&destination=/page.php?var=1&var= 2 ???如果是这样,有人能告诉我怎么做吗?

最佳答案

在将其添加到 URL 之前,您应该使用 urlencode()$destination 进行编码。

基本上,您是将一个值添加到其中包含 & 的 URL,这是一个在 URL 中用于其他目的的特殊字符。服务器看到此字符并正在缩短该值。通过对其进行编码,您应该获得正确的值。

稍后您可以使用 urldecode() 将值恢复为正常值。

关于php - $_SERVER ['REQUEST_URI' ] 和 $_GET,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23092378/

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