开发者

php settting $_GET value

开发者 https://www.devze.com 2023-02-03 20:48 出处:网络
I need to set th开发者_运维技巧e $_GET values; can I do this? ie I have an empty $_GET array. How can make it nonempty with php?

I need to set th开发者_运维技巧e $_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;


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


$_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'


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消