I used to work on a tracking pixel based upon this answer. Unfortunately I have a problem with loading the file which is the source in the image-tag. The pixel-tracker (pixel.php) works as I tried it by addressing the file-URL myself and it inserts data into the database.
Applied on an email, the file won't load. I tried this on two email-providers, Gmail and Yahoo. No response.
Then, because I thought it could be blocked or anything else - who knows - I put it on to my own website. No result. So I assume that the file doesn't get loaded into the image-tag. But how can I solve it?
The image-tag I use is quite simple:
<img src='http://www.mypage.com/data/pixel.php?a=value1&b=value2&c=value3' />
Thanks in advance for any help.
UPDATE: This is the code for the pixel.php-file. It's a bit weird I assume, but works so far if I address the file directly.
<?php
require 'config.php';
// Create an image, 1x1 pixel in size
$im=imagecreate(1,1);
// Set the background colour
$white=imagecolorallocate($im,255,255,255);
// Allocate the background colour
imagesetpixel($im,1,1,$white);
// Set the image type
header("content-type:image/jpg");
// Create a JPEG file from the image
imagejpeg($im);
// Free memory associated with the image
imagedestroy($im);
$ip = $_SERVER['REMOTE_ADDR'];
$useragent = $_SERVER['HTTP_USER_AGENT'];
$sql1 = "INSERT INTO pixel (a, b, c)
VALUES ('$ip','$useragent','$c')";
if ( $mysqli->query($sql1) ){
//header("location: overview.php");
echo "Registration successful!";
}
else {
$_SESSION['message'] = 'Registration failed!';
//header("location: error.php");
echo "Registration failed";
}
?>
Add (for Allen):
My code so far.
<?php
$content = file_get_contents('white_1x1.jpg');
echo base64_encode($content);
header("Content-Type: image/jpeg");
echo base64_decode($content);
//following PHPcode for Log to db
require 'config.php';
$ip = $_SERVER['REMOTE_ADDR'];
$useragent = $_SERVER['HTTP_USER_AGENT'];
$sql1 = "INSERT INTO pixel (a, b, c) VALUES ('$ip','$useragent','$c')";
if ( $mysqli->query($sql1) ){
//header("location: overview.php");
//echo "Registration successful!";
}
else {
$_SESSION['message'] = 'Registration failed!';
//header("location: error.php");
//echo "Registration failed";
}
?>