Files and folder structure

Please could you advise me about file structure.

My structure is currently the following:
Inside main root folder:
index.php
profile.php
inbox.php
users.php

Each main php file has two parts. On top only php which gets all data, handles $_POSTs etc., below I display html without and with php.

Each file has sections. For example profile.php has aboutme, friends, comments, …
I do this by the following way:

//top
if ($_GET[section]=="aboutme"){
  include_once('includes/profile/aboutme_php.php');
}elseif($_GET[section]=="comments"){
  include_once('includes/profile/comments_php.php');
}
//...

//below
?>
<html>
<?
if ($_GET[section]=="aboutme"){
  include_once('/profile/aboutme_html_php.php');
}elseif($_GET[section]=="comments"){
  include_once('includes/profile/comments_html_php.php');
}
//...
?>
</html>

So each bigger page has own folder inside includes folder where are files for each section. Similar is with header and footer, but because they are common to all pages, I have it in includes without subfolder.

Each file have included also settings.php. Settings.php is located outside root for security reasons. And inside settings.php are included functions.php and language.php.

Is ok to have include in parent include (functions.php>settings.php>profile.php)?

Is ok to have in this case for example comment in includes/profile/comments_html_php.php?

Is this common and ok to use this way?

Tnx!

It really depends on the size of you application. For smaller applications your structure would prob suffice, although it’s not particularly scalable.

I assume you write procedural code, obviously larger applications would benefit from the scalability of object orientated code. This takes time to learn so may not be the best option for now.

As a kind of middle-ground you could do something like the following.

Stick with the single point of entrance, maybe move your pages into a pages folder, create a templates folder for each page, a layouts folder for you html layout and store all you js, css and imgs in the public root.

  • public_html
    [LIST]
  • layouts
    [LIST]
  • js
  • css
  • imgs
    [/LIST]
  • pages
    [LIST]
  • js
  • css
  • imgs
    [/LIST]
  • index.php
    [/LIST]
  • …/ - outside of public root
    [LIST]
  • pages
    [LIST]
  • templates
    [LIST]
  • example_template.phtml
  • another_template.phtml
    [/LIST]
  • functions
    [LIST]
  • example_functions.php
  • another_functions.php
    [/LIST]
  • example_page.php
  • another_page.php
    [/LIST]
  • layouts
    [LIST]
  • 1col.phtml
  • 2co.phtml
  • 3col.phtml
    [/LIST]
  • system
    [LIST]
  • settings.php
  • functions.php
    [/LIST]

    [/LIST]

Hope this helps. Others may have better ideas, It’s been a while since I designed a procedural app.

Best Regards, George