Jump to content

php highlighted navigation.


attila2452

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)
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");		}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...