I'm pretty new to PHP and I've started working on a pretty big website so i wonna be sure i'm doing everything right with the website structure or it will be difficult changing everything later. this is how a basic page looks like: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> <link href="StyleSheet.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="MPMain"> <div id="MPLogo"> <?php include("logo.php"); ?> </div> <div id="MPMenu"> <?php include("menu.php"); ?> </div> <div id="MPContent"> <?php if ($logged == 1) { //START LOGGED IN AREA echo" <table width=654><tr><td class=Titlelink valign=top align=center> Main</td></tr></table> "; echo "You are logged in"; // enddddddddddddddddddddddddddddddddddd } else { echo "please log in"; } ?> </div> </div> </body> </html> PHP: as you can see i have the menu and the logo separated, the log in form is part of the menu therefore i'm checking if i'm logged in already in the menu and just setting $logged as 1. so when i create a new page i don't have to worry about all that. as long as the structure is the same (logo, left menu, right content) i can change the design easily but i am wondering if there's a better way of doing that? to contain even less information in every basic page without putting what's left in a different file and including it. another thing i've noticed is that websites are trying to put as many pages as possible in a single php file. for example default.php?page=index default.php?page=users default.php?page=help I can't understand what do you gain by doing that? it just makes the page look long and complicated. and the last thing i need to know is how can i put and retrieve a TextArea from a database in the same format. i can do it easily with txt files but i am worried about overload because i'll create thousands a day. What i have is a bunch of lines, each stored in a variable. i have to store it in a database\(txt file) and show it later to the user later by line. thanks in advance...
well if your planning to lessen ur pages... you need to use ajax, surely that will lessen the redundant script in css/ layout. anyways... might want to check www.w3schools.com
If you dont know what page.php?index=whatever is doing, then let me try to help. There are a number of ways of accomplishing this, but most often people use the $_GET global variable. For example, if in your page.php you put ... <?php if( isset( $_GET['index'] ) ) { $index = $_GET['index']; switch( $index ) { case 'whatever': // Code to do whatever here break; default: // default code to do if no matches break; I often use such an approach. What it does is if the parameter matches, it executes some code. So in our case, whatever matches, so it would run the code in that block. If there were no matches, say the URL was page.php?index=nothing, then the default would run. Read up on it and play around with it. What you gain from it is that you essentially are using 1 file to do numerous actions, cutting down repetition and code. Also, once rewrote, you could have URL like page/whatever.
"What you gain from it is that you essentially are using 1 file to do numerous actions, cutting down repetition and code. Also, once rewrote, you could have URL like page/whatever." -this is what i wanted to know what a specific code is doing it's easy to find by googling -without using ajax, the structure looks fine? it's ok by me, i just wonna make sure i'm doing everything right. and i really need an answer to my last question because it's what i am working on right now.
The structure you're talking about - default.php?page=whatever is basically a style thing. On most sites, most of the pages are going to have a lot of common elements - header, navigation, footer, css, basic javascript. You don't want to have to duplicate that same stuff on every page because if you need to change something you'd have to hunt down tons of files. There are two basic ways to get around that 1) put all the common stuff in individual files that you include on each page or 2) run all of the pages though the same base script. The method you're talking about here is #2. Typically what you want to do with this is make each of your subpages their own file and include them in the master file. In this case your default.php file would look something like: Obviously you'll want to add some error checking, etc to that. You'd make each of your subpages into their own include so that each page's logic doesn't get all mixed up in one huge file. This isn't a horrible approach for a small project. It's probably no better or worse than using individual pages for and including the common stuff on each page. For larger projects though you're going to want to setup a more robust architecture and be sure to separate the logic from the output. As for turning your urls from default.php?page=whatever into just page/whatever you do that with mod_rewrite. You'll find about a gazillion examples of how to do that if you search on mod_rewrite.