Welcome, Guest

Please login or register

TUTORIALS SUBMENU

PHOTOSHOP    FLASH    ILLUSTRATOR    BLENDER    CINEMA 4D    WEB-CODING    [SUBMIT]

Related Links

The Complete Shoutbox Tutorial

pages (3): 1 [2] 3


if ( isset ( $_POST['shout'] ) )
{

$name = addslashes($_POST['name']);
$contact = addslashes($_POST['contact']);
$message = $_POST['message'];

if ( ( isset($name) ) && ( isset($message) ) )
{

// getting smilie list
$smilies = mysql_query("SELECT * FROM smilies") or die(mysql_error());
while($get = mysql_fetch_array ($smilies))
{

$alt = $get['Alt'];
$smilie = $get['URL'];

$message = str_replace( $get['Symbol'] , '<img src="smilies/'.$smilie.'" border="0" width="15" height="15" alt="'.$alt.'">' , $message);
$themessage = addslashes($message);

// replacing all smilies

}

mysql_query("INSERT INTO shouts (Name, Contact, Shout) VALUES ( '$name' , '$contact' , '$message' )") or die(mysql_error());
$_SESSION['has_posted'] = 'yes';
header("Location: shout.php");

// if required fields aren't empty, process into database

} else {

echo '<script>alert("Some fields were not filled out!");</script>';
header("Location: shout.php");

// if required fields were left empty, show an error dialog

}

}

This is a rather large function, but there's no need to panic as its pretty simple in operation, and shows off a couple of anti-spam functions too. As you can probably guess, this function processes the shout submissions and puts them into the database, after replacing smilie symbols with user-defined and uploaded images (see admin.php). Before it does this, though, it checks that the user actually came from the form, which is a useful anti-spam feature and stops some degree of remote hijacking. After this, it checks that all the data fields have been filled in properly on the form and displays a nice big error message if the user doesn't fill out their name or a shout. With all of the checking out of the way, our function then gets all the smilies out of the database, replaces the applicable ones in the shout message, and finally adds slashes before passing it on to be processed.  The shout is then processed and added to the database.

As a final anti-spam measure, the script sets a session to indicate that the user has already posted a message. To post a second message the user would have then to restart their browser.

That’s the shout.php file out of the way! Now we can move onto the admin.php file that allows us to add/delete the shouts, add new smilies, etc.

Breakdown of admin.php
We can skip the “building block” because it’s the same as the one at the start of shout.php. The first block of code in our admin.php file defines the login credentials, i.e. the username and password. Pretty simple really:

$username = "adminuser";
$password = "password";

Next in line is the login checking function:

if ( isset ( $_POST['login'] ) )
{

if (( $_POST['username'] === $username ) && ( $_POST['password'] === $password ))
{

$_SESSION['admin_logged_in'] = 'true';

}

}

This function checks that the login button has been pressed, and the user came from the right place (i.e. OUR script). It then checks that the username and password are correct before setting the session so that the user can see the admin cp.

function selectAction ( $mode )
{

switch ($mode)
{

case '':
echo 'Welcome to the administration panel, make the selection above.';
break;

case 'add':
echo '
<form action="admin.php?mode=posting" method="post" name="addSmilie" enctype="multipart/form-data">
<input name="symbol" type="text" value="=)" size="25" maxlength="4"><br>
<input name="image" type="file"><br>
<input name="addsmilie" type="submit" value="Add Smilie!"><br><br>
Check your symbol and filename, I couldnt be bothered writing an "edit smilie" function. Please note, as this is not a gdlib tutorial, there are no file dimensions protections. Please only upload 15x15 pixel smilies, if they are not this size, they will be skewed when they are resized when displayed.
</form>
';
break;

case 'delete':
$query = mysql_query("SELECT * FROM smilies") or die(mysql_error());
while($row = mysql_fetch_array($query)){

echo '<a href="admin.php?mode=posting&smilie='.$row['id'].'">
<img src="smilies/'.$row['URL'].'" border="0" width="15" height="15" alt="'.$row['Alt'].'">
</a><br><br>
';

}
break;

case 'clear':
mysql_query("TRUNCATE TABLE shouts") or die(mysql_error());
echo 'Shoutbox cleared successfully!';
break;

case 'logout':
$_SESSION['admin_logged_in'] = '';

header("Location: admin.php");
break;

case 'posting':
if(isset($_POST['addsmilie'])){

$uploaddir = 'smilies/';

$uploadfile = $uploaddir . $_FILES['image']['name'];

//echo '<br><br>'.$uploaddir.'<br>'.$uploadfile.'<br><br>';

$upload = move_uploaded_file($_FILES['image']['tmp_name'], $uploadfile);
echo '<pre>';
if( $upload == TRUE ) {

echo 'Success';

} else {

echo 'Error';
print_r($_FILES);
exit;

}
print "</pre>";

$alt = $_FILES['image']['name'];
$symbol = $_POST['symbol'];
$url = $_FILES['image']['name'];

mysql_query("INSERT INTO smilies(Symbol, URL, Alt) VALUES('$symbol','$url','$alt')") or die(mysql_error());
echo '<br><br>Successfully inserted smilie!<br><br><a href="admin.php">Admin</a> | <a href="shout.php">Shouts</a>';
exit;

}

if(isset($_GET['smilie'])){

$smilie = $_GET['smilie'];
mysql_query("DELETE FROM smilies WHERE id = '$smilie' LIMIT 1") or die(mysql_error());
echo 'Successfully deleted smilie!<br><br><a href="admin.php">Admin</a> | <a href="shout.php">Shouts</a>';

}
break;

default:

} // end switch
} // end if

Whoa, this is a big one huh? Let’s break it down into smaller chunks...

- Tutorial written by Scrowler

Pages (3): <Prev 1 [2] 3 Next>
Automatic Translations: Translate Into French Translate Into German Translate Into Italian Translate Into Spanish Translate Into Portuguese

Last 5 User Comments

User:  slepage95 (#63101)
Date: Mon Jun 07, 2010. 00:06:57

Post #4 of 4

Good tutorial^^ Just have one question, is there a way we can add sound when a message is received? Thanks

Reply to this post


User:  s3xyglass3s (#48812)
Date: Mon Mar 17, 2008. 14:07:43

Post #3 of 4

great work :D

I just have one question; how can you separate the action, that you have in the .fla file, and have a separate .as file?

I always get stuck there, and I have to make a shoutbox for school, with a separate .as file..

is it hard? can you show me?

Thnx

Steffy

Reply to this post


User:  Tamlin (#34751)
Date: Wed Nov 22, 2006. 00:25:26

Post #2 of 4

Quote from flores741;34750:
Nice work, but thought I might point out smilies is actually SMILES :D


If you mean these things: :) :) :lol: :ciao:
I think you'll find that in 99.99999% of the web they are called Smilies, not Smiles. :nyanya:

Short for "Smiley Face", I assume.

Reply to this post


User:  flores741 (#34750)
Date: Wed Nov 22, 2006. 00:04:43

Post #1 of 4

Nice work, but thought I might point out smilies is actually SMILES :D

Reply to this post


--- View Entire Thread ---
Amazing Font Pack!

Featured Tutorialsmore

StarBurst Effects
StarBurst Effects
- Adobe Photoshop -
Rotated Characters
Rotated Characters
- Adobe Illustrator -
Photo Frames
Photo Frames
- Adobe Illustrator -
Realistic Metal
Realistic Metal
- Adobe Photoshop -
Membership

Username:
Password:  
Remember Me

Lost Password? || Register

Related Links



Special Options
Download Source File
Printer Friendly Version
Forum Threads

 Deactivate Account
Author: jerinian
Posted: Oct 02nd, 11:16am
Activity: 1 replies, 887 views
 changes....
Author: supertackyman
Posted: Sep 12th, 2:56am
Activity: 2 replies, 1052 views
Back again and with free webhosting :)
Author: ngz
Posted: Aug 14th, 3:50pm
Activity: 0 replies, 1054 views
Cartoon Crab 6 Legs Walk Run created in Blender
Author: patricia3d
Posted: Jun 19th, 12:58pm
Activity: 0 replies, 1935 views
HTML Form Post Array to PHP
Author: Space Cowboy
Posted: May 25th, 2:18pm
Activity: 0 replies, 1832 views
My blog where i create Digi Scrapbook
Author: claudya07
Posted: May 11th, 2:33pm
Activity: 0 replies, 14441 views
Blood Dripping from Letters
Author: patricia3d
Posted: Apr 05th, 3:37am
Activity: 0 replies, 2751 views
A New Designer has joined the ranks
Author: skates1
Posted: Mar 28th, 2:19pm
Activity: 2 replies, 2772 views
The hole in Photoshop
Author: Mars
Posted: Feb 13th, 9:28pm
Activity: 2 replies, 3439 views
Colour Swatch
Author: ebz7350
Posted: Jan 15th, 11:18am
Activity: 0 replies, 2356 views
 BioRUST Forums - Reply to Topic
Author: inonShozy
Posted: Jan 11th, 11:32am
Activity: 8 replies, 2499 views
 Version 2 of my portfolio site.
Author: andrewnleon
Posted: Jan 08th, 6:18am
Activity: 6 replies, 2798 views
Forum Threads

--- Site Resources ---
Total Tutorials:212
Total Downloads:    441
Total Fonts:    4673