Jump to content

php highlighted navigation.


attila2452
 Share

Recommended Posts

so this is my navigation.php

<?php echo"<ul>	<li><a href='/'>Home</a></li>	<li><a href='?page=about'>About</a></li>	<li><a href='?page=portfolio'>Portfolio</a></li>	<li><a href='#'>Contact</a></li></ul>";?>

pretty basic right?well here's my include fucntion for pages.

	<?php		if(isset($_GET["page"]) && $_GET["page"] != "home"){			if(file_exists($_GET["page"].".php")){				include($_GET["page"].".php");			   					echo '<title>'.$title.'</title>'."\n";			echo '<meta name="description" content="'.$meta_description.'" />'."\n";			echo '<meta name="keywords" content="'.$meta_keywords.'" />'."\n";			}else{				include("PageNotFound.php");				}		}else{			include("home.php");		}	?>

now how do i putif page == "home" then background-color: #007FA6;elseif page == about then background..... [else background-color:inherit;end if.how could i approach that?

Link to comment
Share on other sites

you can put a id='activepage' in the (eg. anchor) element by checking the current page position. and you can set separate style for the paritcular id.

Link to comment
Share on other sites

you can put a id='activepage' in the (eg. anchor) element by checking the current page position. and you can set separate style for the paritcular id.
this might sound stupid now how would i impliment it into my php (im learning) Edited by Attila2452
Link to comment
Share on other sites

<style type="text/css"><?php   if ($page == 'home') {	echo "body { background-color:#007FA6 }";  } else echo "body { background-color:inherit }";?></style>

Just so you know, there is a vulnerability in your code. Because you are taking the $_GET values and including them if the file exists and the page is not home, a savvy user can include basically any .php file on your computer. PHP has access to files on the web server that web browser usually don't have access to. Because the user can only include .php files, your script is not as vulnerable as this would be:

		if(isset($_GET["page"]) && $_GET["page"] != "home"){			if(file_exists($_GET["page"])){				include($_GET["page"]);			   					echo '<title>'.$title.'</title>'."\n";			echo '<meta name="description" content="'.$meta_description.'" />'."\n";			echo '<meta name="keywords" content="'.$meta_keywords.'" />'."\n";			} else{				include("PageNotFound.php");				}		}else{			include("home.php");		}

Edited by Fmdpa
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...