Posted on February 21st, 2007
11638 views
Hello,
In this tutorial you'll learn an easy way of navigation using the ?id=pagename feature. BUT YOU MUST READ THIS IN ORDER TO UNDERSTAND IT AND THAT IT WORKS FOR YOU. PS: Notice that this is my first Php tutorial so if you get a little confuse just reply back, but I think you'll do good. DONT FORGET TO VISIT MY SITE ScyberSpace ok Lets start with the whole code. Make a file that you want to use (eg. index.php) if you use index.php the the url will be index. php?id=pagename you are not limited to the name of the file but use a logic name. -index.php- <?Php ok and now lets break it down to understand it Code:$pass = array('tutorials','affiliates','contact_us'); This part of the code will array our pages in this cases it will array tutorials,affiliates,contact_us. To array your more of you own pages simply add the name of another page, so if you have a page name downloads.php you'll just add downloads as it is on the file.( be carefull when adding more pages if they have uppercase, just add it as it is) if (in_array($_GET['page'], $pass)) { Here you'll determine if you want your page to have ?id, ?page or something else, just rename the $_GET['page'] to something else like $_GET['action'] , then your urls would be index.php?action=pagename. In ( '/' ) this part of the code you just establish where the pages are located if the are in the main folder leave it like it is but if is in something like news then name that the pages are in the news directory. Then in the last part again ask us for the $_GET value, you just name it with the same you did in the $_GET value above. And finally you add the extension of the pages you want to load. All pages must be the same extension in this case the all are .php. elseif (!isset($_GET['page'])) { This just loads the default page when you go to index.php. Make sure that the $_GET value is the same from above. else { This final part of the code will just state that if any of the pages you put were not loaded then it will take you to a 4040 error an you just replace with your custom 404 error page at the end where it says ['DOCUMENT_ROOT'] . '/error.php'); I hope you've learn something from here and good luck |