php settting $_GET value

2019-09-12 04:35发布

I need to set the $_GET values; can I do this?

ie I have an empty $_GET array. How can make it nonempty with php?

Maybe with help of http headers?

Thank you in advance;

4条回答
Viruses.
2楼-- · 2019-09-12 04:49

The $_GET array is initially populated from the query string, but you can overwrite that if you want to without redirecting. If at some point in your code you set $_GET['foo'] = 'bar'; then that is set thereafter, no matter what the query string is.

查看更多
小情绪 Triste *
3楼-- · 2019-09-12 04:58

You can try updating $_GET

$_GET['test'] = 'abc';

And then redirect users there:

header('Location: ?' . http_build_query($_GET));

You just have to make sure to redirect only when necessary, so that you don't take users into infinite redirect.

查看更多
Evening l夕情丶
4楼-- · 2019-09-12 05:03

It is three ways of doing this.

One:

<form method="get" action="file.php">
<input type="text" name="TextThing" />
</form>

In the php file:

$_GET["TextThing"]; //contains the text of the texbox TextThing...

Second:

Use a questionmark behind the url, like this: http://domain.com/file.php?foo=bar&stack=overflow

Then:

$_GET["foo"]; //contains bar
$_GET["stack"]; //contains overflow

Remember that your users easily can change the values of the variables.

Third:

$_GET["foo"] = "bar";
$_GET["foo"]; //contains bar
查看更多
等我变得足够好
5楼-- · 2019-09-12 05:06

$_GET is populated with the params/values sent in the querystring of the url, so if you call http://example.com/my.php?foo=bar&foo2=baz then in my.php $_GET['foo'] => 'bar' and $_GET['foo2'] => 'baz'

查看更多
登录 后发表回答