Jump to content


Lots of different files or a switch statement?

  • Please log in to reply
3 replies to this topic

#1 seabro



  • Members
  • PipPip
  • 10 posts

Posted 05 October 2013 - 03:15 AM

Hi all, 


I am a bit of a PHP rookie, never having had any training so I don't really know the best practices.


In the past I have made sites out of lots of different files and more recently I made a whole site in a single index.php which had lots of options in a switch statement.


The single file site was really messy as you can imagine.


What's the norm?  How do you guys find the right balance?





#2 _EmilsM



  • Members
  • PipPip
  • 14 posts

Posted 05 October 2013 - 05:45 AM

I mostly use seperate files with seperate directories for file types, for example, classes or functions, template. Then I can easily tell where what is and can find what I want. Another thing I do is name files according to the content, so I can tell witch file coresponds to what.

#3 davidannis


    Freak Dr.

  • Members
  • PipPipPip
  • 463 posts
  • LocationOkemos, MI USA

Posted 08 October 2013 - 04:34 PM

I generally like to have a few common files

  1. sets globals, opens db connections, etc
  2. header
  3. footer
  4. functions that are used by multiple programs

then I have separate files and include the common ones.

#4 udaystrad


    Advanced Member

  • Members
  • PipPipPip
  • 48 posts

Posted 12 October 2013 - 04:21 AM

People have different style for making a website, u can make it the way u want. All pages are linked together in some way. Usually people follow a common style so that their fellow patners or the next person handling it can understand the flow and that is as follows:-


1. Home page is named as index.php (.php extension is a page made in php, u can use any language or say file extension u want)


2. if u have a commom header and footer for all pages then header.php and footer.php respectively.


3. Pages are named after their purpose, for eg. Contact page -> contact-us.php , About Us page -> about-us.php , Terms of service -> tos.php , etc.


4. All images are saved in Images or Img folder, CSS files is saved in CSS folder, Javascript in js folder


Again u can name the files the way u want. But the above way helps everyone to understand and easily remember wer ur files are.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime