Corsi online:
Una particolare chat che viene più utilizzato nei siti web è la cosiddetta Tag Board o shoutbox. SI tratta di un piccolo spazio, spesso rettangolare dove gli utenti che stanno navigando sul sito possono comunicare tra loro senza bisogno di registrarsi.
Questo tutorial ha l'obiettivo di spiegare come creare un shoutbox (o Tag Board) completo con Php e MySql.
codice SQL per la tabella
potete utilizzare phpmyadmin per incollare il codice ed eseguire la query
CREATE TABLE `shoutbox` (
`postid` int(11) NOT NULL auto_increment,
`poster` varchar(45) NOT NULL default '',
`message` varchar(255) NOT NULL default '',
`date` int(11) unsigned NOT NULL default '0',
`ipadress` varchar(15) NOT NULL default '',
PRIMARY KEY (`postid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Codice dello shoutbox ( versione standalone )
<?php
/**************************************************************/
//| |//
//| Fast Shout Box Script 0.1 |//
//| © RevokeSoft 2006 |//
//| Author : trashofmasters |//
//| Date : 1146068386 |//
//| |//
/**************************************************************/
//limit : INTEGER / NULL if NULL show all messages else show N messages
//dbname: database name
//pass : database password
//host : database host , usually ( 90% cases ) localhost
//user : database username
//lunghezza_minima : INTEGER the minium lenght ( in characters ) of the username and message
//message_default_value : show the default value for message
//username_default_value : show the default value for username
/**********************************************/
/**/ #EDIT UNDER HERE# /**/
/**********************************************/
/**/ $message_default_value = 'Messaggio'; /**/
/**/ $username_default_value = 'Username'; /**/
/**/ $lunghezza_minima = 10; /**/
/**/ $dbname = ''; /**/
/**/ $user = ''; /**/
/**/ $pass = ''; /**/
/**/ $host = 'localhost'; /**/
/**/ $limit = NULL; /**/
/**********************************************/
//connecting to the database
$connection = mysql_connect($host,$user,$pass);
$database = mysql_select_db($dbname,$connection);
if($limit == NULL){
$limit = '';
}else{
$limit = 'LIMIT '.$limit;
}
//extracting messages from the database
$query = 'SELECT * FROM shoutbox ORDER BY date DESC '.$limit;
$select = mysql_query($query);
//check if the form is correctly filled and if the submit button was pressed
if($_GET['act'] == 'post' ){
//check if the directive magic_quotes_gpc is set to 1 in php.ini
//if not escapes all special characters
//else do anything
if(!get_magic_quotes_gpc()){
$poster = addslashes($_POST['username']);
$message = addslashes($_POST['message']);
}else{
$poster = $_POST['username'];
$message = $_POST['message'];
}
//check if the fields are filled
if(empty($poster) or empty($message)){
$error .= '<p class="error">Impossibile Inserire Il Messaggio : Campi Vuoti!</p>';
}
//check if the field are more than $lunghezza_minima characters
if(strlen($poster) < $lunghezza_minima or strlen($message) < $lunghezza_minima){
$error .= '<p class="error">Impossibile Inserire Il Messaggio : Minimo '.$lunghezza_minima.' Caratteri!</p>';
}
//check if the form is submitted only by pressing submit
if($poster == $username_default_value or $message == $message_default_value){
$error .= '<p class="error">Impossibile Inserire Il Messaggio : Valori Di Default Non Ammessi!</p>';
}
}
?>
Codice HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
<title>shout box</title>
<style type="text/css">
.textarea {
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
color: #3C6180;
text-decoration: none;
width: 150px;
padding: 1px;
vertical-align: middle;
border: 2px solid #B3CADD;
}
.shout {
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
color: #009900;
}
.cancel {
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
color: #CC0000;
}
.username {
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
color: #006699;
}
.scrollarea {
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
background-color: #CBDBE4;
border: 2px solid #B3CADD;
width: 150px;
padding: 2px;
}
.success {
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
color: #006600;
background-color: #C4F5BC;
border: 1px solid #009900;
width: 150px;
padding: 2px;
}
.error {
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
color: #CC0000;
background-color: #F4BDBD;
border: 1px solid #CC0000;
width: 150px;
padding: 2px;
}
a{
text-decoration: none;
}
</style>
</head>
<body>
<form id="shoutpost" method="post"
action="?act=post">
<table width="162" border="0"
cellpadding="1" cellspacing="1">
<tr>
<td width="156" class="scrollarea"
style="vertical-align: top; height: 200px;">
<marquee direction="up"
scrollamount="1">
Codice PHP:
<?php
//fetching the messages
while($shout = mysql_fetch_array($select)){
//un-escape the string
if(get_magic_quotes_gpc()) {
$mex = stripslashes($shout['message']);
}else{
$mex = $shout['message'];
}
//show the messages and convert them timestamp into a human readable date
echo '<span class="username">'.$shout['poster'].'</span> : <br />'.$mex.'<br />'.date('d/m/Y H:i:s',$shout['date']).'<br />'; }
?>
Codice HTML:
</marquee></td>
</tr>
<tr>
<td><input name="username"
type="text" class="textarea"
id="username" onfocus="this.value=('')"
value="<?php echo $username_default_value; ?>" size="80"/></td>
</tr>
<tr>
<td><input name="message"
type="text" class="textarea"
id="messaggio" onfocus="this.value=('')"
value="<?php echo $message_default_value; ?>"
maxlength="255"/></td>
</tr>
<tr>
<td><input name="Submit"
type="submit" class="shout"
value="Urla" />
<input name="Submit2" type="reset"
class="cancel" value="Cancella"
/></td>
</tr>
</table>
</form>
Codice PHP:
<?php
//check if there is any error
if(!empty($error))
{
echo $error;
}elseif(isset($_POST['Submit'])){
//if there aren't submit data into database
$query = "INSERT INTO shoutbox (poster,message,date,ipadress) VALUES ('".$poster."','".$message."','".time()."','".$_SERVER['REMOTE_ADDR']."');";
$ins = mysql_query($query);
if($ins)
{
//success message
echo '<p class="success">Messaggio Inserito Con Successo <a href='.$_SERVER['PHP_SELF'].'>aggiorna</a></p>';
}
}
?>
Codice HTML:
</body>
</html>
Fonte: http://forum.tutorialweb.org/showthread.php?p=4111#post4111
- Current TV di Al Gore in Italia: su Internet e Sky TV. Programmi, trasmissioni, funzionamento.
Current TV, la televisione di Al Gore, arriva in Italia. Si potrà vedere sia via web che su Sky.
- Offerte Internet con cellulare per navigare e scaricare e-mail: Tim e Wind
- Iab Forum a Roma 2008: pubblicità Internet in Italia in crescita, ma chiesto sostegno del Governo
- WiMax: rete mobile per coprire tutti gli Stati Uniti. Alleati Google, Intel, Sprint. Progetto al via
- Pubblicità su Hotmail e Live Messanger: ricavi in beneficenza. Ottima accoglienza degli utenti.
- Soluzione problema delle PNG con IE 6: hack
La versione 6 del noto browser di casa Microsoft ha sempre avuto problemi di renderizzazione dei file PNG8. Varrà la pena cercare di supportarli? - OpenOffice 3.0 disponibile da scaricare gratis per tutti. Novità e funzioni
- Musica e video su P2P nascondono virus e trojan: rilevati in poche ore 360mila tentate infezioni da un unico nuovo worm. E' già accaduto in passato, ma vi è una forte crescita
- Errori di programmazione applicazioni e siti web: software DrangonFly Opera li controlla direttamente online facendo il debugging.Gratis da scaricare
- Windows Xp service pack 3 italiano rilasciato uficialmente da Microsoft. Installazione e soluzioni per possibili problemi
- Carta per stampante che si cancella utilizzabile 100 volte: elevato risparmio aziendale e minor inquinamento toner e inchiostri
- Creare file excel con PHP


![[SPONSOR] 9NetWeb (Link Esterno)](http://www.webmasterpoint.org/sponsor/9netweb_120.gif)
![[SPONSOR] Aruba (Link Esterno)](/sponsor/aruba_90.gif)
![[SPONSOR] ConsultingWeb (Link Esterno)](/sponsor/consultingweb_120.gif)
Stampa Pagina
Info sull'autore
ICQ
EMAIL
DISCUTI DI QUESTA LEZIONE SUL FORUM![[SPONSOR] eDomain (Link Esterno)](http://www.webmasterpoint.org/sponsor/edomain_120.gif)

