PDA

View Full Version : proper way to build a forum?



DarkMathias
August 14th, 2008, 12:28 PM
does anyone know what is required, what language, anything to build a forum on a site.

the athletic group i'm a part of wants me to build a site with forum capabilities, and i am stuck on forums, i've been reading up but still puzzled, any help by anyone would be appreciated.

thank you.:beer2:

brianmanden
August 14th, 2008, 12:45 PM
Why build it yourself ?

There are plenty of open source forums you can download for free.

DarkMathias
August 14th, 2008, 12:47 PM
i prefer to understand the whole coding, so I can be a better programmer after college. it comes down to the point that i want to be able to set up the forum my way.

Charleh
August 14th, 2008, 01:34 PM
Well one way which is probably the most popular is to use a backend database and write the front end in either ASP/ASP.NET or PHP.

You basically store all of your data in the database, be it Access, SQL2000/2005, MySQL etc and use that to determine the data in your site.

The PHP/ASP loads the data and formats it for use on the site.

A good way to do it is to write a templating system as this will allow you to modify the look and feel of the site rather than embedding all your HTML code in the PHP pages as some people do.

Depending on your forums complexity your database can contain all sorts - but most of the time you will need users, forum topics, posts, access levels (security) and that will probably get you started.

Your database will sit on a server and your PHP/ASP pages may sit on the same server or a different one, but they will need access to the database server. Most hosts allow some sort of database with PHP and MySQL being a common and cheap option.

I would be inclined to start with ASP.NET however - the tools are quite easy to get to grips with (Visual Studio) and you can download it free from Microsoft. Just Google 'Visual Studio Express Web Developer Edition' and you will find it easy. Download that and install and you can pretty much get started right away, however .NET hosting is more expensive generally than PHP hosting.

How much knowledge do you have of programming in general? Do you need a description of how the whole dynamic web process works?

samboy
August 14th, 2008, 10:24 PM
Well one way which is probably the most popular is to use a backend database and write the front end in either ASP/ASP.NET or PHP.

You basically store all of your data in the database, be it Access, SQL2000/2005, MySQL etc and use that to determine the data in your site.

The PHP/ASP loads the data and formats it for use on the site.

A good way to do it is to write a templating system as this will allow you to modify the look and feel of the site rather than embedding all your HTML code in the PHP pages as some people do.

Depending on your forums complexity your database can contain all sorts - but most of the time you will need users, forum topics, posts, access levels (security) and that will probably get you started.

Your database will sit on a server and your PHP/ASP pages may sit on the same server or a different one, but they will need access to the database server. Most hosts allow some sort of database with PHP and MySQL being a common and cheap option.

I would be inclined to start with ASP.NET however - the tools are quite easy to get to grips with (Visual Studio) and you can download it free from Microsoft. Just Google 'Visual Studio Express Web Developer Edition' and you will find it easy. Download that and install and you can pretty much get started right away, however .NET hosting is more expensive generally than PHP hosting.

How much knowledge do you have of programming in general? Do you need a description of how the whole dynamic web process works?

Yes please if you dont mind. Thanks

Charleh
August 16th, 2008, 07:34 AM
Ok well I'll do the whole lot - starting with the whole client/server thing.

When you are browsing the net you are basically sending a request for content to several different computers on the net each time you click on a link or navigate to a new page. The internet knows which computer to talk to based on the URL you supply. All PCs on the net have an IP address. A system called the DNS system links the domain names (www.google.com (http://www.google.com)) to the IP addresses. You can check the IP address of a domain by using nslookup in the command prompt ("nslookup www.google.com")

A domain is broken into a few pieces - for example www.google.com/somepage.html?start=yes (http://www.google.com/somepage.html?start=yes)

www is the subdomain
google is the second level domain
com is the top level domain
somepage.html is the page request
start=yes is a 'query' string known as the request string or the 'get' string in PHP (these can be quite long, not sure on the maximum length - might want to look it up - I'll come back to this on the dynamic pages bit below)

You can read up on domain names at these links - it's a bit heavy going though (http://en.wikipedia.org/wiki/Domain_name | http://en.wikipedia.org/wiki/Top-level_domain)

There's a lot more to it but in the end your request will eventually get to the correct PC - so for instance if you type www.google.com (http://www.google.com) the request will eventually reach the Google servers.

Your request can also contain extra data known as the POST data - this is embedded with your page request and usually contains the details of form submissions etc (if you click submit after entering some data on an HTML form)

Once your request hits the server - based on the server setup and the actual URL you accessed a page will be 'served' to you (hence 'server'). The server sends the content of the page you requested back down the line for your computer to interpret. How your computer interprets the information is based on the browser you are using (IE may display some content slightly differently from Firefox etc).

A request with no page request specifier such as www.google.com (http://www.google.com) will usually call the 'default' page. This is a setting which is done at the server level and tells the server which page to serve if nothing specific is requested (usually index.htm or index.html but can be anything)

For pages written in plain HTML the page will not change. i.e. if you request www.someurl.com/somthing.html (http://www.someurl.com/somthing.html) if the page is purely HTML the page will always look the same until a new version is uploaded to the server. The page is static.

An HTML page can be dynamic by the use of javaScript, but it's usually reserved for interactivity rather than data retrieval. Check out some of the microsoft MSDN sites as they tend to use a lot of javaScript for pop up windows, rollover menus and text toggling (click to hide/show portions of text).

Dynamic pages are what you need to get rich interactive content such as forums. It's probably possible to use javaScript embedded in the HTML pages to build a forum site but put it this way - I've been developing for years and years and I wouldn't want to give it a try!

The dynamic page works in much the same way as the static page - however once your request gets to the server, before the server sends the page back, it performs some modification to the HTML code, possibly even building the entire page from code.

The code in a dynamic page is never visible to the client - it is stripped out by the code parser before the page is sent (be it ASP/PHP etc), so all the client ever sees is the HTML code which is the finished article.

The POST data and REQUEST/QUERYSTRING data can also be used by the code at the server end - so depending on the querystring data or the post data a page can interpret this and modify the HTML it sends back.

A dynamic page may also make use of a database. If you aren't familiar with databases theres a quick overview at the end.

So let's take a PHP as an example:

Let us assume that you have downloaded the PHP installer from the PHP website and that you have installed IIS on your local PC (this can be found in Add/Remove programs - Windows Components and comes as part of XP Pro as standard). Once you have run the IIS installer, run the PHP installer. This will register the required components with IIS and should only take a moment to install.

Now that PHP is installed your IIS server will know that any pages requested with a .PHP extension should be sent to the PHP parser before they are served to the client. You can change all these settings in IIS if needs be.

There is nothing special about a PHP page in terms of it's format - it's simply a plain text file with a .PHP extension. PHP can be embedded in HTML pages or a page can be purely PHP.

Open up notepad - or if you have a good HTML editor like Dreamweaver or the like use that instead as it will have code hinting and colour coding to make things easier to read.

Type the following code:



This is a PHP test page
<br>
<?php
if(isset($_GET["message"])) {
echo "Message was set in the querystring, hello world!";
} else {
echo "Message was not set in the querystring, oh dear!";
}
?>
This is a simple piece of code which checks to see if the querystring contains a parameter called 'message' and displays a piece of text accordingly.

Save the page and put it in your 'c:\inetpub\wwwroot\' directory - call it 'test.php'

Browse to http://localhost/test.php and your page will be shown with the 'oh dear' message.

Change the URL to http://localhost/test.php?message=something and you will see the 'hello world' message.

Now you have a dynamic page working! The rest is outside the scope of this article, when you get this far, check out the PHP manual from the PHP website. There are a lot of resources to get going with PHP - learn about sessions, data access and logins/security

Database overview:

If you are unsure about databases, they are simply a method of storing large amounts of data and retrieving it quickly. This data is usually 'relational' which means that data in certain parts of the database relates to data in other parts of the database.

Data in databases is held in 'tables' each of which have one or more 'columns' or 'fields' of varying data types (text, number, binary etc).

The data in these tables will usually relate to each other by one or more fields - for example a list of cars in a garage linked to a list of owners.

Programming languages can connect to the database to retrieve information based on 'queries' which are pieces of code which retrieve certain bits of data.

For example your forum may contain a list of posts made by users in a table - we may be looking for all the posts by one particular user

The query may look like



SELECT * FROM Posts WHERE UserName = 'Charleh'
Which means select all columns (*) from the posts table where the username equals 'Charleh'. This language is known as SQL (structured query language)

With this knowledge you can create a relational database which can store information about users/posts/security/news bulletins etc etc and use PHP to query the data and display it on the pages the user requests. This is how most forums are built.

There are some good examples on wikipedia

http://en.wikipedia.org/wiki/Database
http://en.wikipedia.org/wiki/Sql

Anyway, I suggest you get stuck in and then ask questions later! It's easy to get started, but the scope of these technologies are very wide so it can take decades to become a master!