Jragon Posted July 6, 2010 Share Posted July 6, 2010 What is Sliger? Sliger is a Smart loger of ip adresses Why the name Sliger? well Silger stands for: S=Smart L=loger I=IP GER=the end bit on loger Why is it smart? well it is not smart yet but hay i got as much time as i want (i'm only 12) Features 1.0: logs ip to txt file desplays ip 2.0: logs ip to txt file desplays ip only logs the ip if there is not allready a ip in the text file Sliger 1.0: The file The source code: <?php //finds out ip $ip = $_SERVER['REMOTE_ADDR']; //path to ip logs file direcotry $path = 'directory to store logs'; //path to log file $logfile = 'log file name'; //construct path $absLogfile = $path . $logfile; //looks to see if dose not file exits if (!file_exists($absLogfile)) { //makes the file $f = fopen($absLogfile, 'w+'); }else{ //opens the file redy to wright $f = fopen($absLogfile, 'a+'); //wittes the ip to the file fwrite($f, $ip."\n"); //closes the file fclose($f); } //echo's the ip echo $ip; ?> Sliger 2.0: The Page chek it out: <?php //finds out ip $ip = $_SERVER['REMOTE_ADDR']; //path to ip logs file direcotry $path = 'PATH TO LOG FILE'; //path to log file $logfile = $path . 'LOG FILE NAME'; //looks to see if dose not file exits if (!file_exists($logfile)) { //makes the file $f = fopen($logfile, 'w+'); }else{ //opens the file redy to wright $f = fopen($logfile, 'a+'); //looks for data from log file $data = fread($f, filesize($logfile)); //looks to see if there is a ip thats the same $pos = strpos($data, $ip); //if in $pos there is no ip thats the same as the ips logged if ($pos != true) { //wittes the ip to the file fwrite($f, $ip . "\n"); //closes the file fclose($f); }else if($pos != false){ echo "This IP address is already recorded. <br />"; } } echo $ip ?> How to install 2.0: 1. make a text file with the info "Logz:" 2. upload it to your log dir 3. upload your sliger file Sliqer 1.0: Features Logs IP to a database Code: <?php //Start Configeration //database host address $host = 'jragoncouk.ipagemysql.com' //username to the database $user = 'ipadmin' //database password $pass = 'md50i' //database name $dbname - 'iplog' //table to be used $tbname = 'logged_ips' //End Configeration //finds out ip $ip = $_SERVER['REMOTE_ADDR']; //conects to the mysql server $connection = mysql_connect($host, $user, $pass); //sellects the database mysql_select_db($connection, $dbname); //inserts the ip in to the database $query = 'INSERT INTO `' . $dbname . '` (`Address_ID`, `Address_IP`, `Address_visits`); VALUES (\'0\', \'' . $ip . '\', \'1\');'; mysqli_query($connection, $string); //echos the ip echo $ip; ?> MySQL Table make code: CREATE TABLE `logged_ips` ( `Address_ID` int(11) NOT NULL auto_increment, `Address_IP` varchar(68) NOT NULL, `Address_Visits` int(11) NOT NULL, PRIMARY KEY (`Address_ID`) ) ENGINE=MyISAM AUTO_INCREMENT=38 DEFAULT CHARSET=latin1 AUTO_INCREMENT=38 ; Sliqer 2.0(beta) Features Logs IP only if IP is not allreadey logged adds a Visit if ip is allready logged Code: <?php //Start Configeration //database host address $host = '**' //username to the database $user = '**' //database password $pass = '**' //database name $dbname - 'iplog' //table to be used $tbname = 'logged_ips' //End Configeration //finds out ip $ip = $_SERVER['REMOTE_ADDR']; //conects to the mysql server $connection = mysqli_connect($host, $user, $pass); //sellects the database mysql_select_db($connection, $dbname); //looks for duplacute ips $dup = getFields($dbname, $tbname); //checks to see if there is a duplecate name if(mysql_num_rows($dup) !> 0){ //inserts the ip in to the database $query = 'INSERT INTO `' . $dbname . '` (`Address_ID`, `Address_IP`, `Address_visits`); VALUES (\'0\', \'' . $ip . '\', \'1\');'; mysql_query($connection, $string); }else{ //adds a visit to the database $string2 = "UPDATE `logged_ips` SET `Address_visits` = '++1' WHERE `ip_address` = $ip LIMIT 0,1"; mysql_query($connection, $string2) or die('Error: ' mysql_error); } //echos the ip echo $ip; ?> MySQL Table make code: CREATE TABLE `logged_ips` ( `Address_ID` int(11) NOT NULL auto_increment, `Address_IP` varchar(68) NOT NULL, `Address_Visits` int(11) NOT NULL, PRIMARY KEY (`Address_ID`) ) ENGINE=MyISAM AUTO_INCREMENT=38 DEFAULT CHARSET=latin1 AUTO_INCREMENT=38 ; I am still encontering some errors... Please correct my liqer 2.0 i dont know what is wron with it Thanks to: Mark for helping me with the errors Joel who gave me the idea Tea for keeping me up all night Me for the programming P.S. this is my first project i have tried with out a tutorial so please dont be too harsh P.P.S if you think the comments are bad please repace them with better ones Link to comment Share on other sites More sharing options...
Recommended Posts