Jump to content

Recommended Posts

I'm making an Image IP loggers, here's the code:

(I call this file 1.php)

<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
# SETTINGS:
$imagelink = "http://mysite.com/dir/l.gif";
# END SETTINGS

$fp = fopen('logs.txt', 'a');  # File will be created if (!exist) :-)

$ip = $_SERVER['REMOTE_ADDR'];
$agent = $_SERVER['HTTP_USER_AGENT'];
$port = $_SERVER['REMOTE_PORT'];
$file = $_SERVER['HTTP_REFERER'];   # External page (viewed from this page)

fwrite($fp, " Ip: ".$ip);
fwrite($fp, " User-Agent: ".$agent);
fwrite($fp, " Port: ".$port);
fwrite($fp, " File: ".$file);
fwrite($fp, "\n");
fclose($fp);

header("content-type: image/gif");
$image = ImageCreateFromGIF($imagelink);
imagegif($image);
ImageDestroy($image);

exit(); # Force exit (Reason: forum keeps loading)
?>

 

Here's the error:

The image “http://mysite.com/dir/1.php” cannot be displayed, because it contains errors.

 

What am I doing wrong?

Link to comment
https://forums.phpfreaks.com/topic/128465-image-ip-logger/
Share on other sites

probably errors

try commenting out the header( line; and see if an error appears

here a quick re-write

<?php
ob_start();
ini_set('display_errors', 1);
error_reporting(E_ALL);
# SETTINGS:
$imagelink = "http://mysite.com/dir/l.gif";
# END SETTINGS

$fp = fopen('logs.txt', 'a');  # File will be created if (!exist) :-)

$ip = $_SERVER['REMOTE_ADDR'];
$agent = $_SERVER['HTTP_USER_AGENT'];
$port = $_SERVER['REMOTE_PORT'];
$file = $_SERVER['HTTP_REFERER'];   # External page (viewed from this page)

fwrite($fp, " Ip: ".$ip);
fwrite($fp, " User-Agent: ".$agent);
fwrite($fp, " Port: ".$port);
fwrite($fp, " File: ".$file);
fwrite($fp, "\n");
fclose($fp);
ob_end_clean();
if(!file_exists($imagelink))
{
die("Fail to load file");
}
header("content-type: image/gif");
$image = ImageCreateFromGIF($imagelink);
imagegif($image);
ImageDestroy($image);
exit(); # Force exit (Reason: forum keeps loading)
?>

Link to comment
https://forums.phpfreaks.com/topic/128465-image-ip-logger/#findComment-665741
Share on other sites

When I comment that out I get this:


Warning: imagecreatefromgif() [function.imagecreatefromgif]: 'l.gif' is not a valid GIF file in /home/****/public_html/mysite.com/dir/1.php on line 28

Warning: imagegif(): supplied argument is not a valid Image resource in /home/****/public_html/mysite.com/dir/1.php on line 29

Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/****/public_html/mysite.com/dir/1.php on line 30

Link to comment
https://forums.phpfreaks.com/topic/128465-image-ip-logger/#findComment-665754
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.