Home > php教程 > php手册 > body text

php获得url参数中具有&的值的方法

WBOY
Release: 2016-06-13 09:41:55
Original
1954 people have browsed it

实际在项目过程中,我们经常会遇到要获取上一页地址的路径。你可以返回上一页使用

复制代码 代码如下:


<script>window.history.go(-1);</script>


这个是通过JS来操作的

如果出现这样的场景,当用户需要退出帐号,你又希望他退出后直接在返回当前页面

比如,当前页面的地址为http://xxx/module.php?module=groupbook&view=index&id=2.

你退出系统想必会使用 $_SERVER['REQUEST_URI'] 来 获取当前路径,然后把这个值做为参数传给退出需要返回的路径,这个时候你回发现

他只获取了http://xxx/module.php?module=groupbook 却没有得到&view=index&id=2,也就是说我们退出后返回的地址变成了

http://xxx/module.php?module=groupbook(本应该是http://xxx/module.php?module=groupbook&view=index&id=2),

这是因为他把&当成第一个的参数了,简单理解为

http://xxx/login.php?op=logout&return=http://xxx/module.php?module=groupbook&view=index&id=2,

变成了

http://xxx/login.php?op=logout&return=http://xxx/module.php?module=groupbook&view=index&id=2。

这个时候我们需要对当前获取的$_SERVER['REQUEST_URI'] 进行转码使用urlencode($_SERVER['REQUEST_URI'])

就可以解决我们的问题
Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!