I have a url of the format /?var1 = val1&var2 = val2;
I want to check for the presence of just var2 = val2 in the url using php. How can that be done?
do this
if (isset($_GET['var2'])) // check if exist
{
if ($_GET['var2'] == val2) // do something
}
if (isset($_GET['var2']) && $_GET['var2'] == val2). Due to short-circuiting.If this is not the QUERY_STRING for the request (in which case you should just use $_GET as @Spechal said), you can use parse_str(). It "uses the same mechanism that PHP uses to populate the $_GET, $_POST, etc. variables."
See also parse_url().