Hi there,
My problem is quite simple, but I can't figure out how to word it into a simple search term, so I am asking here.
I want to use a php include for a website. The include contains the navigation for the site, which follows this format:
<ul id="nav">
<li><a href="home.php" class="active">Home</a></li>
<li><a href="about.php">About</a></li>
<li><a href="contact.php">Contact</a></li>
</ul>
What I'm trying to do is define the active state of the particular navigation item for each page. So in pseudo-code speak, I want this to happen:
If the URL is equal to "www.mysite.com/about.php", then show "class="active" in the link for the "About" navigation item.
I know how to do this using ExpressionEngine, by writing:
{if segment_1 == "about.php"} class="active" {/if}
So how do I do it using straight PHP? Thanks for the help! Snarky comments aren't needed, so don't bother plzthx.
If *url exists*, then show this code...
Moderator: General Moderators
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: If *url exists*, then show this code...
Something like:
Code: Select all
if(basename($_SERVER['PHP_SELF']) == 'about.php') echo 'class="active"';mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
- ColonelSandersLite
- Forum Commoner
- Posts: 35
- Joined: Sun May 09, 2010 1:32 am
Re: If *url exists*, then show this code...
I think you're asking how to get the current script's filename right?
This information can be found with the $_SERVER superglobal.
Since the documentation on what's readily available in the superglobals kinda sucks just put this in a php file to see everything
This information can be found with the $_SERVER superglobal.
Since the documentation on what's readily available in the superglobals kinda sucks just put this in a php file to see everything
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?PHP
echo "\n<pre>";
echo "\n\$GLOBALS\n";
print_r($GLOBALS);
echo "\n\$_SERVER\n";
print_r($_SERVER);
echo "\n\$_GET\n";
print_r($_GET);
echo "\n\$_POST\n";
print_r($_POST);
echo "\n\$_FILES\n";
print_r($_FILES);
echo "\n\$_REQUEST\n";
print_r($_REQUEST);
echo "\n\$_SESSION\n";
print_r($_SESSION);
echo "\n\$_ENV\n";
print_r($_ENV);
echo "\n\$_COOKIE\n";
print_r($_COOKIE);
echo "\n\$php_errormsg\n";
print_r($php_errormsg);
echo "\n\$HTTP_RAW_POST_DATA\n";
print_r($HTTP_RAW_POST_DATA);
echo "\n\$http_response_header\n";
print_r($http_response_header);
echo "\n\$argc\n";
print_r($argc);
echo "\n\$argv\n";
print_r($argv);
echo "\n</pre>";
?>
</body>
</html>
Re: If *url exists*, then show this code...
AbraCadaver: that did it, thanks!