hello i want to share my script to log ip address player
konek.php
iplogin.php
iplogin.sh
ok this is my script, thank you and sorry if i'm wrong
edit : i'm sorry, im forget about database, this is my table
thank you
konek.php
<?php
function open_connection()
{
$host="localhost";
$username="your_username";
$password="your_password";
$databasename="pw";
$link=mysql_connect($host,$username,$password) or die ("Database tidak dapat dihubungkan!");
mysql_select_db($databasename,$link);
return $link;
// setting timer
$lama = 2;
$query = "DELETE FROM iplogin WHERE DATEDIFF(CURDATE(), date) > $lama";
$hasil = mysql_query($query);
}
?>
iplogin.php
<?php
// ----- ambil isi dari file koneksi.php
require("konek.php");
// ----- hubungkan ke database
$link=open_connection();
// ----- menentukan nama tabel
$tablename="iplogin";
// ----- perintah SQL dimasukkan ke dalam variable string
$sqlstr="select * from $tablename";
// ------ jalankan perintah SQL
$result = mysql_query ($sqlstr) or die ("Kesalahan pada perintah SQL!");
// ------ putus hubungan dengan database
mysql_close($link);
// ------ buat tampilan tabel
echo("<table width=500 border=1>");
echo("<tr><td >DATE</td><td>JAM</td><td>MENIT</td><td>ACCOUNT</td><td>USER_ID</td><td>IP ADDRESS</td></tr>");
// ------ ambil isi masing-masing record dari tabel mysql
while ($row = mysql_fetch_object ($result))
{
// ----- mengambil isi setiap kolom dari tabel mysql
$date=$row->date;
$hour=$row->hour;
$minute=$row->minute;
$account=$row->account;
$user_id=$row->user_id;
$ip_login=$row->ip_login;
// ------ menampilkan di layar browser seperti mozila firefox
echo("<tr><td>$date</td><td>$hour</td><td>$minute</td><td>$account</td><td>$user_id</td><td>$ip_login</td></tr>");
}
echo("</table>");
iplogin.sh
#!/bin/sh
// COMMENT : THIS IS SCRIPT BASE FROM RBB138
cd /root/pwserver/logs
grep -e ':account=:' world2.formatlog > iplogin.formatlog
chmod 777 iplogin.formatlog
sed -i 's/ /,/g' iplogin.formatlog
sed -i 's/=/,/g' iplogin.formatlog
sed -i 's/:/,/g' iplogin.formatlog
sed -i 's/,,,/,/g' iplogin.formatlog
sed -i 's/,,/,/g' iplogin.formatlog
mysqlimport --local -uroot -h127.0.0.1 -pPASSWORD --force --columns=date,hour,minute,@x,@x,@x,@x,@x,@x,@x,account,@x,user_id,@x,@x,@x,ip_login --fields-terminated-by=, pw /root/pwserver/logs/iplogin.formatlog
rm iplogin.formatlog
ok this is my script, thank you and sorry if i'm wrong
edit : i'm sorry, im forget about database, this is my table
CREATE TABLE IF NOT EXISTS `iplogin` (
`date` varchar(40) NOT NULL,
`hour` varchar(10) NOT NULL,
`minute` varchar(10) NOT NULL,
`account` varchar(35) NOT NULL,
`user_id` int(20) NOT NULL,
`ip_login` varchar(35) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
thank you
Last edited: