Immediately following the code above, we analyze the contact information. Contact information should
be in the form of email or url of their website. This code will check if mailto: or http:// exists.
And if it does not, we will add it onto whatever they typed. P.S: this method is borrowed from
misterhaan. Look below:
Flood Control
Next we will execute code aimed at preventing multiple comments duing one setting. We run a query that
selects comments matching their IP. Then check if the last comment was made within 5 minutes, if so-
tell them to stop posting so fast, if not- allow the comment to fall through. Here is the code:
Inserting The Comment and Refreshing the Page
This is the final portion of the code. After this is complete, we display the form to submit
a comment. Anyways, we will run an insert query to add the data. The submit button has been pressed,
the input data has been validated, and we're all ready. After the insert query executes, we
use header(); to refresh the page and show the poster their comment. Observe:
Notice we're using addslashes(); to insert the data into the database. And the values from the
form submission are available through $_POST. The input fields are assigned a name, and we put
that name inside $_POST to access it specifically.
*Note: Notice the article id is accessed by $_GET. That is because in this situation, the article
id number is available in the URL, like this: site.com/article.php?id=XXX .
And at the end, is where we're refreshing the page. If this does not work for you, you might try
using, ob_start(); at the top of your script. This might fix a reload problem - should it arise.
At the end you see, "#comments". This is an anchor name I setup in the code of the article where
I put the code to insert comments for that page. So by adding this to the end of the header(); it
will refresh down to comments by the anchor. That is basic HTML.
You can indeed
add smilies. I
don't have an
article up on
BBCode, but you
basically use
regular
expression
(regex)
functions like:
preg_match()
font> and
preg_replace()
and
also
str_replace()
to replace the
BBCode
characters in
the message to
HTML.
For example:
You want to use
:) as a smilie.
You would use
str_replace to
replace :) with
HTML path to
the smilie.
Then, store
that in the DB.
When you
display it, it
displays hte
smilie.
preg_replace
and preg_match
using regex are
for the more
complicated
BBcode items,
like quotes and
links and such.
Good luck!