Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5


Catching IP Address?
03-03-2010, 04:50 AM (This post was last modified: 03-03-2010 04:52 AM by Sixaxis.)
Post: #1
Catching IP Address?
The following must first be set up onto a website (Free hosting would work just fine).

Code:
Base Code

<?php

//--> Edit these details.
$databaseDetails = Array(
        'Host'  =>      'localhost',
        'Port'  =>      'dbport',
        'Name'  =>      'dbname',
        'User'  =>      'dbusername',
        'Pass'  =>      'dbpassword'
        
);

//-->The path to the image you wish to display.
$imageFileName = 'myNeowinSig.jpg';

//--> Lets go!

//--> Checking the image exists.
if ( @file_exists($imageFileName) && (function_exists('imagejpeg')))
{
        //--> Collecting visitor information
        $vistorIP               =       addslashes((getenv(HTTP_X_FORWARDED_FOR)) ? getenv(HTTP_X_FORWARDED_FOR) : getenv(REMOTE_ADDR));
        $visitorReferrer        =       addslashes(( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : 'Referrer undetectable.');
        $visitorBrowser =       addslashes(( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : 'Browser undetectable.');
        
        //--> Logging details to database
        $con = mysqli_connect($databaseDetails['Host'],$databaseDetails['User'],$databaseDetails[
'Pass'],$databaseDetails['Name'],$databaseDetails['Port']) or die();
        $sql = "INSERT INTO `imageLog` (IP , Referrer , Browser , Timestamp )VALUES( '{$vistorIP}' , '{$visitorReferrer}' , '{$visitorBrowser}' , now() )";
        $res = mysqli_query($con,$sql) or die();
        
        //--> Sending JPEG image header to browser.
        header("Content-Type: image/jpg");
        
        $myImage = imagecreatefromjpeg($imageFileName);
        
        //--> Sending image to user.
        imagejpeg($myImage);
}
?>

Now for the testing part.

If Embedding On A Site (Use this to test the image on your site before trying to broadcast it?)
Code:
<img alt="Sorry, image unavailable." src="http://yourServer/imageScript.php" />
Find all posts by this user
Quote this message in a reply
04-02-2010, 08:59 PM
Post: #2
RE: Catching IP Address?
Is this meant to record poster's ip? I mean to keep track? or nonetheless to be able to know which ip address to ban?

eToys coupons
Pinoy Earns Green!
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:

Bad Bot Trap - Do Not Click!