跟踪像素的网址不会加载文件

时间:2017-07-26 09:14:57

标签: php html

我曾经根据this answer处理跟踪像素。不幸的是我在加载文件时遇到了问题,该文件是图像标签中的来源。像素跟踪器(pixel.php)通过自己解决文件URL并将数据插入数据库来尝试它。

在电子邮件中应用,不会加载该文件。我在两个电子邮件提供商,Gmail和雅虎上试过这个。没有反应。

然后,因为我认为它可能被阻止或其他任何事情 - 谁知道 - 我把它放在我自己的网站上。没有结果。所以我假设文件没有加载到image-tag中。但是我该如何解决呢?

我使用的图像标签非常简单:

<img src='http://www.mypage.com/data/pixel.php?a=value1&b=value2&c=value3' />

提前感谢您的帮助。

更新: 这是pixel.php文件的代码。我认为这有点奇怪,但是如果我直接处理文件,它会起作用。

<?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";
    }    
?>

添加(对于艾伦):

到目前为止我的代码。

<?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";
    }
?>

1 个答案:

答案 0 :(得分:0)

对于你的情况:

  1. 为PHP转换为文本准备1像素图像
  2. 将图像二进制数据缓存到PHP代码中

        <?php
            $content = file_get_contents('white_1x1.jpg');
            echo base64_encode($content);
        ?>
    
  3. 回显二进制数据并将数据记录到数据库中

        <?php
            $content = 'a long string value from step 2';
            header("Content-Type: image/jpeg");
            echo base64_decode($content);
            //following PHPcode for Log to db
        ?>
    
  4. 最后代码:

    <?php
        $content = '/9j/4AAQSkZJRgABAQEAwADAAAD/2wBDAAIBAQIBAQICAgICAgICAwUDAwMDAwYEBAMFBwYHBwcGBwcICQsJCAgKCAcHCg0KCgsMDAwMBwkODw0MDgsMDAz/2wBDAQICAgMDAwYDAwYMCAcIDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAz/wAARCAABAAEDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD9/KKKKAP/2Q==';
        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";
        }
    ?>