admin管理员组文章数量:1391987
We always retrieve the value in a $_GET['var']
, but is it possible to assign a value as well? I have a php page where at one point, through ajax, I want to stay on the same page but change the query string or do an assignment like this:
$_GET['myvar'] = 'newvalue';
Is this possible?
We always retrieve the value in a $_GET['var']
, but is it possible to assign a value as well? I have a php page where at one point, through ajax, I want to stay on the same page but change the query string or do an assignment like this:
$_GET['myvar'] = 'newvalue';
Is this possible?
Share Improve this question asked Apr 29, 2013 at 13:52 user961627user961627 12.8k43 gold badges148 silver badges212 bronze badges 5- The $_GET variable is just equal to your URL query params . You can change your query string and your work will be done. There is no point to override $_GET – Svetoslav Commented Apr 29, 2013 at 13:56
- How can the query string be changed while on the same page? Is it possible through javascript? – user961627 Commented Apr 29, 2013 at 14:03
- 1 1st and best way is to redirect to grab current query and to refresh page (redirect) to next page .. Other way is with changing browser history(but this works on newer browsers only) - html5demos./history/first – Svetoslav Commented Apr 29, 2013 at 14:08
- Thanks but I need to change the querystring without redirecting the page. Is this possible? – user961627 Commented Apr 29, 2013 at 14:10
- html5demos./history/first - go here there is what you want.. – Svetoslav Commented Apr 29, 2013 at 14:13
3 Answers
Reset to default 2Yes you can override the $_GET. however that is only for that request.
with ajax you do a new request and in the ajax call you can just use diffrent values for the data.
Yes, you can assign to the $_GET array, but it won't change the query string in the URL.
It's probably not the wisest thing to do though, as it will be overwritten in the next request
$_GET
is just like a regular array. The only difference is that the keys of this array will be automatically populated with values that e with the request using HTTP GET. They are called superglobals because they are automatically and globally available anywhere in your script, other wise they behave just like regular arrays.
So if you have a request like mypage.php?key=value
, PHP automatically does something equal to this for you:
$_GET['key'] = 'value';
And just like any regular array, you can overwrite it with a different value. However I really do not see a use case for that unless you are doing some testing or some really weird thingy..
本文标签: phpassign a new value to a GET variableStack Overflow
版权声明:本文标题:php - assign a new value to a $_GET variable - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744716659a2621444.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论