Reputation: 315
Is it possible to make an IF clause in php that will only trigger if i have encoded a specific variable in the url?
I have a php page which will get and output query results without page refresh. When a user clicks on a specific query result, that value is sent via url to the same page which then reruns this script with that query result as the new search parameter.
Only thing is, first time the page is run i need to find a way to bypass the echo statements and the attempts to $_GET data from the url, because there is none.
so essentially some kind of if clause that could be like
IF(url variable value = 'id')
{
$variabledata=$_GET['var1'];
echo $variabledata;
}
ELSE nothing
Upvotes: 1
Views: 71
Reputation: 57322
you can check this when you get the url
if (isset($_GET['var1']) && $variabledata=$_GET['var1']) {
echo $variabledata;
}
Upvotes: 1
Reputation: 58601
$_REQUEST
works for GET
and POST
if($_REQUEST['url_variable_value'] == 'id'){
$variabledata=$_GET['var1'];
echo $variabledata;
} else {
// nothing
}
// http://example.com/somewhere/?url_variable_value=id&var1=the_data
// output: "the_data"
Upvotes: 0
Reputation: 50613
You can do it like this:
if (isset($_GET['var1'])) {
$variabledata=$_GET['var1'];
echo $variabledata;
}
so the content of the if
block will only be executed if the parameter var1
was sent.
Upvotes: 3