atrum Posted April 2, 2010 Share Posted April 2, 2010 Hello all, I am looking for some feed back on getting my navigation script a little cleaner. My goal is to try and keep my site as dynamic as possible with out redundant code. So here are the important bits. Site: http://tools.exiled-alliance.com/vpsexpert.new/ Common config: config.php Master page: index.php Navigation Script: inc.redirect.php Ok, here is the setup. On the Master page, I want this to be a staging area for site content. The content is control from the Navigation script that is included in the content area on the Master page. The Common Config page houses frequently used $vars At the moment only the register, login, and master page are done to the point that I can display them effectively. Now that you have an idea of how I am setup, here is what I need advice on. I am looking for any suggestions or maybe some pointers on how I can do this better, or just cleaner. Here is how the redirect works in pseudo code. if:$page isset { check if . or / exists in the $page var if so then include error page else begin switch statement for $directory case dir1: case dir2: ect ect if $directory matches a case : then include $path = $page / $directory. if the $path does not exist, then include error page. } if page is not set, then include $path = $directory / $homepage. Sorry if that pseudo code is horribly formatted. Here is the actual redirect code. <?php /*Declare GET vars*/ $page = $_GET['pg']; //Page var $folder = $_GET['act']; //Directory Var if($page) //if page var is not nothing { if(!strpos($page,".")||!strpos($page,"/")) //Check for any . or / in the page var. { switch($folder) //Begin switch statement. Check what value $folder contains. { case admin: $path = $admin_root. "/" .$page. ".php"; break; case cpan: $path = $member_root. "/" .$page. ".php"; break; default: $path = $doc_root. "/" .$page. ".php"; } if(file_exists($path)) //If the path exists { include($path); //Display path. } else { include($lib_root. "/errors/inc.404.php"); //Page not found error. } } else { $ip = getenv("REMOTE_ADDR"); //Get the visitors ip address echo "<h2>WARNING!</h2>Hacking will not be tolerated, <br />Your IP ::".$ip.":: has been logged<br />"; exit; //Stop the script from continuing. } } else { $path = $inc_root. "/" .$homepage; if(file_exists($path)) //If the path exists. { include($path); //Display path. } else { include($lib_root. "/errors/inc.404.php"); //Page not found error. } } ?> Also, here is the config file just in case you need to reference something from it. <?php $domain_root = "http://tools.exiled-alliance.com/vpsexpert.new"; /*Domain Root*/ $doc_root = $_SERVER['DOCUMENT_ROOT'] ."/vpsexpert.new"; /*Root of VPSexpert*/ $lib_root = $doc_root ."/lib"; /*Library Root*/ $inc_root = $doc_root ."/lib/inc"; /*Includes Root*/ $admin_root = $doc_root ."/admin"; /*Admin Root*/ $member_root = $doc_root ."/membership"; /*Member Root*/ /*General Config*/ $date = date("F j, Y"); //todays date. $homepage = "inc.stats.php"; //Default Home Page. /*Basic Authentication Check*/ ?> Please be aware that this site is a work in progress, and some parts are not done, but the important pieces for this post are there. I look forward to your replies. Thanks, Atrum, Novice php Programer Quote Link to comment https://forums.phpfreaks.com/topic/197410-looking-for-a-little-feed-back-on-navigation-script/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.