Antes de nada como los grupos malos de música... dejadme que por la cara A cante y por la cara B pida disculpas ya que mi nivel de programación en php es -100. Os comento, tenemos en una pagina de una asociacion de amiguetes un chat de Ajax. El problema es que está abierto a todo el mundo y claro se están empezando a producir ciertas faltas de respeto. Me gustaría que me ayudaseis con el código para que registrase las IP de los que escriben algo así como la hora y fecha a la que lo escriben por si tuviesemos que tomar medidas. Aquí va el codigo.
Código PHP:
<?php
/*
Plugin Name: Jalenack's Wordspew
Version: 1.15
Author URI: http://blog.jalenack.com
*/
// Version of this plugin. Not very useful for you, but for the dev
$jal_version = "1.15";
// The number of comments that should show up in one viewing.
$jal_number_of_comments = 100;
/*** ensure this file is being included by a parent file */
//$path_to_mambo = "/var/www/joomla";
if(defined( '_VALID_MOS' )) {
require_once("configuration.php");
} else {
require_once("../configuration.php");
}
//require_once($path_to_mambo."/configuration.php");
$user = $mosConfig_user;
$db = $mosConfig_db;
$host = $mosConfig_host;
$pass = $mosConfig_password;
$prefix = $mosConfig_dbprefix;
$live = $mosConfig_live_site;
# Get the right language if it exists
if (file_exists($mosConfig_absolute_path.'/components/com_shoutbox/languages/'.$mosConfig_lang.'.php')) {
include($mosConfig_absolute_path.'/components/com_shoutbox/languages/'.$mosConfig_lang.'.php');
} else {
include($mosConfig_absolute_path.'/components/com_shoutbox/languages/english.php');
}
// Register globals - Thanks Karan et Etienne
$jal_lastID = isset($_GET['jal_lastID']) ? $_GET['jal_lastID'] : "";
$jal_user_name = isset($_POST['n']) ? $_POST['n'] : "";
$jal_user_url = isset($_POST['u']) ? $_POST['u'] : "";
$jal_user_text = isset($_POST['c']) ? $_POST['c'] : "";
$jalGetChat = isset($_GET['jalGetChat']) ? $_GET['jalGetChat'] : "";
$jalSendChat = isset($_GET['jalSendChat']) ? $_GET['jalSendChat'] : "";
// Time Since function courtesy
// http://blog.natbat.co.uk/archive/2003/Jun/14/jal_time_since
// Works out the time since the entry post, takes a an argument in unix time (seconds)
function jal_time_since($original) {
// array of time period chunks
$chunks = array(
array(60 * 60 * 24 * 365 , _JAL_YEAR , _JAL_YEARS),
array(60 * 60 * 24 * 30 , _JAL_MONTH , _JAL_MONTHS),
array(60 * 60 * 24 * 7, _JAL_WEEK , _JAL_WEEKS),
array(60 * 60 * 24 , _JAL_DAY , _JAL_DAYS),
array(60 * 60 , _JAL_HOUR , _JAL_HOURS),
array(60 , _JAL_MINUTE , _JAL_MINUTES),
);
$original = $original - 10; // Shaves a second, eliminates a bug where $time and $original match.
$today = time(); /* Current unix time */
$since = $today - $original;
// $j saves performing the count function each time around the loop
for ($i = 0, $j = count($chunks); $i < $j; $i++) {
$seconds = $chunks[$i][0];
$name = $chunks[$i][1];
$names = $chunks[$i][2];
// finding the biggest chunk (if the chunk fits, break)
if (($count = floor($since / $seconds)) != 0) {
break;
}
}
$print = ($count == 1) ? '1 '.$name : "$count {$names}";
if ($i + 1 < $j) {
// now getting the second item
$seconds2 = $chunks[$i + 1][0];
$name2 = $chunks[$i + 1][1];
$names2 = $chunks[$i + 1][2];
// add second item if it's greater than 0
if (($count2 = floor(($since - ($seconds * $count)) / $seconds2)) != 0) {
$print .= ($count2 == 1) ? ', 1 '.$name2 : ", $count2 {$names2}";
}
}
return $print;
}
////////////////////////////////////////////////////////////
// Functions Below are for submitting comments to the database
////////////////////////////////////////////////////////////
// When user submits and javascript fails
if (isset($_POST['shout_no_js'])) {
if ($_POST['shoutboxname'] != '' && $_POST['chatbarText'] != '') {
jal_addData($_POST['shoutboxname'], $_POST['chatbarText'], $_POST['shoutboxurl']);
jal_deleteOld(); //some database maintenance
//setcookie("jalUserName",$_POST['shoutboxname'],time()+60*60*24*30*3,'/');
//setcookie("jalUrl",$_POST['shoutboxurl'],time()+60*60*24*30*3,'/');
//take them right back where they left off
header('location: '.$_SERVER['HTTP_REFERER']);
} else echo "You must have a name and a comment";
}
//only if a name and a message have been provides the information is added to the db
if ($jal_user_name != '' && $jal_user_text != '' && $jalSendChat == "yes") {
jal_addData($jal_user_name,$jal_user_text,$jal_user_url); //adds new data to the database
jal_deleteOld(); //some database maintenance
}
function jal_addData($jal_user_name,$jal_user_text,$jal_user_url) {
global $jal_number_of_comments, $user, $host, $db, $pass, $prefix;
//the message is cut of after 500 letters
$jal_user_text = substr($jal_user_text,0,500);
$jal_user_name = substr(trim($jal_user_name), 0,18);
// CENSORS .. default is off. To turn it on, uncomment the line below. Add new lines with new censors as needed.
//$jal_user_text = str_replace("fuck", "****", $jal_user_text);
$jal_user_text = utf8_encode(jal_special_chars(trim($jal_user_text)));
$jal_user_name = (empty($jal_user_name)) ? "Anonymous" : jal_special_chars($jal_user_name);
$jal_user_url = ($jal_user_url == "http://") ? "" : jal_special_chars($jal_user_url);
$conn = mysql_connect($host, $user, $pass);
mysql_select_db($db, $conn);
mysql_query("INSERT INTO ".$prefix."liveshoutbox (time,name,text,url) VALUES ('".time()."','".mysql_real_escape_string($jal_user_name)."','".mysql_real_escape_string($jal_user_text)."','".mysql_real_escape_string($jal_user_url)."')", $conn);
}
//Maintains the database by deleting past comments
function jal_deleteOld() {
global $jal_number_of_comments, $user, $host, $db, $pass, $prefix;
$conn = mysql_connect($host, $user, $pass);
mysql_select_db($db, $conn);
$results = mysql_query("SELECT * FROM ".$prefix."liveshoutbox ORDER BY id DESC LIMIT ".$jal_number_of_comments, $conn);
while ($row = mysql_fetch_array($results)) { $id = $row[0]; }
if ($id) mysql_query("DELETE FROM ".$prefix."liveshoutbox WHERE id < ".$id, $conn);
}
//if ($jalGetChat != "yes" && $jalSendChat != "yes") {
if(defined( '_VALID_MOS' )) {
?>
<div id="shoutbox">
<div id="chatoutput">
<?php
global $jal_number_of_comments, $mosConfig_offset, $mosConfig_live_site, $mainframe;
$sql = "SELECT * FROM #__liveshoutbox ORDER BY id DESC LIMIT 20";
$database->setQuery( $sql );
$results = $database->loadObjectList();
// Will only add the last message div if it is looping for the first time
$jal_first_time = true;
// Loops the messages into a list
if($results) {foreach( $results as $r ) {
// Add links
$r->text = preg_replace( "`(http|ftp)+(s)?:(//)((\w|\.|\-|_)+)(/)?(\S+)?`i", "<a href=\"\\0\">«link»</a>", $r->text);
if ($jal_first_time == true) { echo '<div id="lastMessage"><span>'._JAL_LAST_MESSAGE.':</span> <em id="responseTime">'.jal_time_since( $r->time ).' '._JAL_AGO.'</em></div>
<ul id="outputList">
'; }
if ($jal_first_time == true) $lastID = $r->id;
$url = (empty($r->url) && $r->url = "http://") ? $r->name : '<a href="'.$r->url.'">'.$r->name.'</a>';
echo '<li><span title="'.jal_time_since( $r->time ).'">'.stripslashes($url).' : </span>'.convert_smilies(" ".stripslashes($r->text)).'</li>
';
$jal_first_time = false; }
// If there is less than one entry in the box
} else {
echo "You need <b>at least one entry</b> in your shoutbox! Just type in a message now and reload, then you should be fine.";
}
$use_url = false;
$use_textarea = false;
?>
</ul>
</div>
<form id="chatForm" method="post" action="index.php">
<p>
<?php
if ( $my->id ) {
echo "\n";/* If they are logged in, then print their nickname */ ?>
<label><?php echo _CONTACT_NAME; ?><em><?php echo $my->username; ?></em></label>
<input type="hidden" name="shoutboxname" id="shoutboxname" value="<?php echo $my->username; ?>" />
<?php
if (!$use_url) {
echo '<span style="display: none">';
} ?>
<label for="shoutboxurl">url:</label>
<input type="text" name="shoutboxurl" id="shoutboxurl" value="" />
<?php
if (!$use_url) {
echo "</span>";
} ?>
<?php
} else {
Siento escribir tal parrafada pero despues de una tarde vagando por tutoriales etc etc ya lo dejo por imposible por mi mismo. Comparando con los registros en mySQL de otras opciones he creado un campo ip (varchar (15)) y otro campo llamado date (datetime) para almacenar los datos en la tabla. Se que para alguien que sepa un poco de PHP esto será una tonteria rapidisima pero para mi significaria muchisimo. Me gustaría también que me indicarais si debo modificar algo mas. Por cierto he tenido que recortar el código que no cabia.. si necesitais la otra parte decirmelo y la pego. Muchisimas gracias por adelantado. Un saludo