代码之家  ›  专栏  ›  技术社区  ›  Daan Goumans

PHP跟踪像素数据库插入

  •  0
  • Daan Goumans  · 技术社区  · 9 年前

    为了跟踪哪个人打开了我的邮件,我想添加一个跟踪像素。

    现在生成了像素,但每当我向url添加GET参数时,它就不起作用了

    我的“pixel.php”代码

    <?php
    
    /* 
    GET Methods 
    */
    if (!empty($_GET)){
        $ip = $_SERVER['REMOTE_ADDR'];
    
    // (Do|log) act on name
    if (isset($_GET['name'])) { 
        $name = $_GET['name'];
    } else{
        $name = "";
    }
    
    // (Do|log) act on mail/campagne id
    if (isset($_GET['mailid'])) {
    
    $id = $_GET['mailid'];
    }else{
        $id = "";
    }
    
    // (Do|log) act on date
    if (isset($_GET['date'])) {
    
    $date = $_GET['date'];
    } else{
        $date = "";
    } 
    
    insert($ip, $name, $mailid, $date);
    
    }else{
    // normal browsing to pixel.php without parameters set
    // no insert here
    }
    
    /*
    INSERT
    */
    function insert($ip, $name, $mailid, $date){    
    
    // Create connection
    $conn = mysqli_connect("192.168.****.****", "****", "****", "maildata");
    if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
    }
    $query  =  "INSERT INTO opened (ip, name, mailid, date)
    VALUES ('".$ip."', '".$name."', '".$mailid."', '".$date."')";
    
    if (mysqli_query($conn, $sql)) {
        echo "New record created successfully";
    } else {
        echo "Error: " . $sql . "<br>" . mysqli_error($conn);
    }
    
    mysqli_close($conn);
    
    }
    
    
    
    /*
    GENERATE IMAGE
    */
    
    // 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);
    
    /*
    
    call with <img src="pixel.php?userid=98798&campaign=302&last=8"> for example
    
    */
    ?>
    

    我认为错误在INSERT mysql语句中的某个地方,但我不知道在哪里,我得到的唯一反馈是“找不到图像”图标

    1 回复  |  直到 9 年前
        1
  •  0
  •   Daan Goumans    9 年前

    mysqli_query($conn, $sql);

    需要

    mysqli_query($conn, $query);