busboy
March 6, 2011, 3:34pm
1
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;
system
March 6, 2011, 4:17pm
2
There are several ways to do it… one is:
$url = $_SERVER["REQUEST_URI"];
if (substr($url, strrpos($url, "/")) == "profile.php") {
// Do stuff
}
busboy
March 6, 2011, 4:32pm
3
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
system
March 6, 2011, 4:42pm
4
LOL yeah, not sure what I was thinking… lose the parse_url, and instead of $url[“path”], use $_SERVER[“REQUEST_URI”]