How do i set the variable that the $_GET
function will be able to use, w/o submitting a form with action = GET
?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
The
$_GET
variable is populated from the parameters set in the URL. From the URLhttp://example.com/test.php?foo=bar&baz=buzz
you can get$_GET['foo']
and$_GET['baz']
. So to set these variables, you only have to make a link to that URL.For the form, use:
and for getting the value, use the get method as follows:
One way to set the
$_GET
variable is to parse the URL usingparse_url()
and then parse the$query
string usingparse_str()
, which sets the variables into the$_GET
global.This approach is useful,
Result:
$_GET
contains$_GET
contains the keys / values that are passed to your script in the URL.If you have the following URL :
Then
$_GET
will contain :Of course, as
$_GET
is not read-only, you could also set some values from your PHP code, if needed :But this doesn't seem like good practice, as
$_GET
is supposed to contain data from the URL requested by the client.If you want to fake a $_GET (or a $_POST) when including a file, you can use it like you would use any other var, like that:
You could use the following code to redirect your client to a script with the _GET variables attached.
This will cause the script to redirect, make sure the
die();
is kept in there, or they may not redirect.