views:

220

answers:

3

Im new with php. Have some questions on how to build. I include everything in index.php. Ex:

ob_start..
html...
functions etc..

if ($_GET['page'] == "forum") include('forum.php');
elseif ($_GET['page'] == "profile") include('profile.php');
else error...etc

/html...

I do it this way because I dont like to have to include a page in top of all page with information i need. Is there i better way then this 2? How do you structure your pages?

Exuse my english but i think you understand ;)

Remy

+1  A: 

Check out this question. The accepted answer has a good take on the most popular routing options. Personally, I use something resembling the Front Controller way.

Paolo Bergantino
A: 

For examples of common good practices in developing your site architecture, coding style and all other things PHP I would suggest that you take a look at one of the common frameworks for PHP. Please note that even if you don't want to use one, it can show you good practices with your code and the comments can be quite informative.

I would personally suggest Zend Framework.

Noah Goodrich
+1  A: 

I do something similar to what you're doing, but coded a little more elegantly:

switch ($_GET['page']( {
    case 'forum':
    case 'profile':
    case 'home':
     include($_GET['page'].'.php');
     break;
    default:
     include('error.php');
}
Phantom Watson