你可以写,创建并返回一个脚本
.gif,
.jpeg或者
.png使用PHP使用跟踪目的图像GD库(在现代版本的PHP往往分布)。如果您无权访问GD,则始终可以在启用GD的情况下重新编译PHP。
例:
pixel.php(为便于说明起见):
<?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);?>在一个简单的示例中,您可以使用电子邮件或其他页面中的以下示例URL调用此跟踪像素:
<img src="http://example.com/pixel.php?a=value1&b=value2&c=value3">
使用变量:
在你的
pixel.php你就可以分析和解释任何
$_GET传递给它的图像标签,简单地内的变量:
if (isset($_GET['a'])) { // (Do|log) act on a}if (isset($_GET['b'])) { // (Do|log) act on b}if (isset($_GET['c'])) { // (Do|log) act on c}根据需要进行应用和重复,但是您可以非常复杂地进行操作,尤其是可以通过在
$_GET字符串上设置var来访问有关用户的大量信息。
一个更适用的示例可能是:
<img src="http://example.com/pixel.php?userid=98798&campaign=302&last=8">
不仅跟踪$ _GET变量:
您还可以使用PHP获取更多信息,例如:
// Server variables$ip = $_SERVER['REMOTE_ADDR'];$referer = $_SERVER['HTTP_REFERER'];$useragent = $_SERVER['HTTP_USER_AGENT'];$browser = get_browser(null, true);etc...
然后将其插入数据库的跟踪表中:
$sql = "INSERT INTO campaign_tracking ('when','campaign','last','ip','useragent') VALUES (NOW(),'$campaign','$last','$ip','$useragent')";这是一种广泛用于跟踪电子邮件营销活动的基本方法,特别是在PHP中,但是相同的方法也可以用于其他脚本/编程语言和库,也可以用于其他目的。
有关GD的更多有用信息:
- GD参考 -在php.net上



