How do i set the variable that the $_GET
function will be able to use, w/o submitting a form with action = GET
?
One way to set the $_GET
variable is to parse the URL using parse_url()
and then parse the $query
string using parse_str(), which sets the variables into the $_GET
global.
This approach is useful,
function setGetRequest($url)
{
$query = parse_url($url, PHP_URL_QUERY);
parse_str($query, $_GET);
}
$url = 'http://www.example.com/test.php?a=10&b=plop';
setGetRequest($url);
var_dump($_GET);
Result: $_GET
contains
array (
'a' => string '10' (length=2)
'b' => string 'plop' (length=4)
)