How to detect a keyword in $_SERVER['QUERY_STRING']

I use this little piece of code below to find out the URL that is currently in the person’s web browser. How can I compose an IF statement to see if the URL has profile.php in it?

Thanks!!

function iif($expression, $returntrue, $returnfalse = ‘’) {
return ($expression ? $returntrue : $returnfalse);
}

$page = “http://{$_SERVER[‘HTTP_HOST’]}{$_SERVER[‘PHP_SELF’]}”;
$page .= iif(!empty($_SERVER[‘QUERY_STRING’]), “?{$_SERVER[‘QUERY_STRING’]}”, “”);

$_SESSION[‘recentPage’] = $page;

There are several ways to do it… one is:


$url = $_SERVER["REQUEST_URI"];
if (substr($url, strrpos($url, "/")) == "profile.php") {
    // Do stuff
}

I think I’m getting close, but when I implemented your example I got the following error:

Warning: parse_url() expects at least 1 parameter, 0 given in /home3/records/public_html/siteHeader.php on line 56

LOL yeah, not sure what I was thinking… lose the parse_url, and instead of $url[“path”], use $_SERVER[“REQUEST_URI”]