1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Putting all PHP files together in the root folder. Good or Bad?

Discussion in 'PHP' started by eritrea1, Jul 22, 2012.

  1. #1
    Hi all,
    SEMrush
    I was just wandering about best way to place all php files in your directories, since I put all files (settings/registration/login/db-connection/index.php ... ) together in the root except the style.css ( which is in ' css/style.css ' ).

    Anyway, is this practice vulnerable to hacks? Or do people just create different folders to make their site feel neat or is it for another reason?

    I would love your intake on this.


    thanks :)
     
    eritrea1, Jul 22, 2012 IP
    SEMrush
  2. programming.russia

    programming.russia Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #2
    I always put all php files in the root. One folder is for backend, one folder is for frontend.
     
    programming.russia, Jul 22, 2012 IP
  3. Rainulf

    Rainulf Active Member

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    85
    #3
    Nothing wrong with it.. but it's good practice to have a folder where all public files are (index.php, style.css, etc), and a private folder where sources/files no need for public to access.

    Also, make sure your permissions are set properly.
     
    Rainulf, Jul 22, 2012 IP
  4. johnafeem

    johnafeem Peon

    Messages:
    45
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    There is no problem in putting PHP files in roots , permissions need to be set properly
     
    johnafeem, Jul 22, 2012 IP
  5. PK-Host

    PK-Host Guest

    Messages:
    109
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #5
    Folders are used simply for neatness oh and sometimes so that permissions can be set but if you have a properly configured server and dont leave your folders open to 777 then you can put your files where ever you want, putting them in appropiate folders help you organise your website better.
     
    PK-Host, Jul 23, 2012 IP
  6. jestep

    jestep Prominent Member Premium Member

    Messages:
    3,661
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #6
    This might work for a very simple php app, but for complex ones, it is a really bad idea. Not only is the organization very poor, but it can really complicate things when trying to include file, or in the event that files have the same names or have classes with the same names.

    It's hard to answer specifically on your usage, but I would always segment files in at least a logical organization based on functionality. If you ever move up into framework development, it is a good idea to get used to separating files. In most MVC usage, all of the files will be in the appropriate directories under root, and none except an index and debugging and testing files will be publicly accessible in the home directory.
     
    jestep, Jul 23, 2012 IP