Anonymous asked in Computers & InternetProgramming & Design · 1 decade ago

How can I write a forum in PHP?

I basically want phpBB, but I want to write it from scratch. How would I go about doing that?


I have a database and a login system and everything like that. I need to know how to store posts and enable the use of BBCode etc.

4 Answers

  • 1 decade ago
    Favorite Answer

    You certainly are not wasting your time, contrary to what JD said. Creating forums is a very effective way of teaching yourself PHP, as it deals with a lot of the main concepts involved in the language, and can also range from very simple to a highly complex product.

    The first thing you should be doing is deciding on what features you want your forum to have. Don't worry too much on what you are capable of currently, and what you think you'll be capable of later. You can always drop features later on, but it becomes rather messy to add new features as you go, since it might conflict with code you've already written.

    Write out a plan on paper listing these features, as well as what pages you intend to have, and what they will do. Also, you should definitely design your database structure (to store all of the information that users submit) before you actually jump into the coding.

    You may find it easier to do this once you've actually had a little bit of experience with things like databases and whatnot, but that is not to say that you should be well versed. Skim a few online articles on the subject matter, and get a general feel for it. Then plan, then build.

    There are tutorials on the net that you can easily find using google, so I'll simply list some topics that you should look into, and describe them.

    PHP Form Processing - An extremely important part of a forum is the ability to post, which is always done using an HTML form. The data from the form is then processed using PHP and then stored.

    MySQL Databases - The most common database system used alongside PHP, available with the majority of hosts that provide php. This allows you to store data (ie: user's account information, threads, posts, etc), as well as retrieve it and output it into your webpage.

    Cookies - Fairly important; cookies are used to store information locally (on a user's computer). This is often used in login scripts (though I would suggest using them alongside information stored in the mysql database). Using cookies you can keep a user 'logged in' for long periods of time, something I don't think you can manage with sessions (Don't quote me on this, as I have never actually made use of sessions).

    Regular Expressions - this is rather complicated, and is used in things such as 'BBCode'. Using it with BBCode, however, isn't too hard, and there are a lot of tutorials that touch on that specific application. Or at least, I think there are.

    Like I said before, this is an excellent way to learn - it is actually somewhere along the lines of my very first PHP project. Of course, don't worry yourself if it takes a long time, as it very well might. Nothing is worse than working for a month and then running out of steam with absolutely nothing complete to show for it.

  • 1 decade ago

    Well... a good place to start would be learning about using sessions in PHP. Unless you want anonymous posters, you'll have to create a login system, and the most common way to do that is with sessions and cookies.

    You also need to design your database, and then it's just a matter of building the code that inserts and selects to/from it.

    Source(s): Built a small forum for a web development class once... good experience, but at the same time, you have to wonder why so many people want to reinvent the wheel. ;)
  • 5 years ago

    I prefer to use SMF (Simple Machines Forum). This is also open source, so you don't have to pay for it. If you just want to download it to look at the code, you can do that too.

  • Anonymous
    1 decade ago
Still have questions? Get your answers by asking now.