johnsmith153 Posted July 7, 2010 Share Posted July 7, 2010 What is the best way to set up PHP pages? Option 1: = many pages like this: <?php //all required info require_once('pagefiles/essentialStuff.php'); //more important stuff require_once('pagefiles/importantStuff.php'); ?> //all html / head tags etc //bespoke info for each page Option 2: = Using one page for everything (index.php) and using index.php?page=adduser / index.php?page=showusers etc... Or another way?? I suppose loads of page1.php, page2.php, page3.php isn't the best way?? Quote Link to comment https://forums.phpfreaks.com/topic/207063-best-way-to-set-up-php-pages/ Share on other sites More sharing options...
marcus Posted July 7, 2010 Share Posted July 7, 2010 <?php include "global.php"; // would be your file that includes functions, database connectivity, etc.. include "header.php"; // would be your file that is the chunk of HTML code that your page would start off with $page = $_GET['page']; if($page){ if(file_exists("pages/".$page.".php")){ include "pages/".$page.".php"; }else { include "pages/404.php"; } }else { include "pages/home.php"; } include "footer.php"; // would be your file that closes the open chunk of HTML from header.php ?> Or if you don't want to use the file_exists method <?php include "global.php"; // would be your file that includes functions, database connectivity, etc.. include "header.php"; // would be your file that is the chunk of HTML code that your page would start off with $page = $_GET['page']; $pages = array('home','about','contact'); if($page){ if(in_array($page,$pages)){ include "pages/".$page.".php"; }else { include "pages/404.php"; } }else { include "pages/home.php"; } include "footer.php"; // would be your file that closes the open chunk of HTML from header.php ?> Quote Link to comment https://forums.phpfreaks.com/topic/207063-best-way-to-set-up-php-pages/#findComment-1082719 Share on other sites More sharing options...
johnsmith153 Posted July 7, 2010 Author Share Posted July 7, 2010 How bad is it to use loads of different php pages that are accessed in the url? Of course they would all have relevant includes (global.php and header.php as mentioned above). Facebook seem to have lots of different php pages, and I am sure many others. Are they doing it wrong? Quote Link to comment https://forums.phpfreaks.com/topic/207063-best-way-to-set-up-php-pages/#findComment-1082732 Share on other sites More sharing options...
KevinM1 Posted July 7, 2010 Share Posted July 7, 2010 Larger apps are typically written in an object oriented style, with each class being stored in its own file and included dynamically when needed. If that doesn't make any sense, don't worry about it. Put another way - large apps are written in a way that makes them flexible to change and easier to maintain than what you're used to seeing/writing yourself. Lots of files is a byproduct of this programming style. Quote Link to comment https://forums.phpfreaks.com/topic/207063-best-way-to-set-up-php-pages/#findComment-1082738 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.