I am working on an email tracking script which inserts a blank GIF linked to my record.php file into the email body, and is supposed to run a script whenever the recipients opens the mail.
The email part is working fine, but I cannot manage to get the verification check nor the data insert working. Anyone mind having a look?
record.php
<?php
error_reporting(E_ALL);
//Begin the header output
header('Content-Type: image/gif');
if(isset($_GET['type']) && $_GET['type'] == 'Poststay') {
// Start MySQLi connection
include '../../../plugins/MySQL/connect_db.php';
$mysqli = new mysqli($dbhost,$dbuser,$dbpass,$dbname);
if($mysqli->connect_errno > 0){
die('Unable to connect to database [' . $mysqli->connect_error . ']'); }
// define and sanitize GET variables
$type = $_GET['type'];
$holidex = $_GET['holidex'];
$user = $_GET['user'];
$sent_to = $_GET['sent_to'];
$crs = $_GET['crs'];
// check if submitted record already exists
$sql = "SELECT Holidex FROM qci_email_log WHERE Holidex = '".$holidex."' AND CRS = '".$crs."'";
if(!$result = $mysqli->query($sql)) {
die('Unable to check for existing records in DB [' . $mysqli->error . ']'); }
if( $result == 0 ) {
$sql = "INSERT INTO `qci_email_log`(`Type`,`Holidex`,`User`,`Sent_To`,`CRS`) VALUES ('".$type."','".$holidex."','".$user."','".$sent_to."','".$crs."')";
if(!$result = $mysqli->query($sql)) {
die('Unable to insert email logging into database [' . $mysqli->error . ']'); }
}
// free result and close connection
$result->free();
$mysqli->close();
}
// disregarding if the database was affected, output an empty image
// URI to the image
$graphic_http = 'http://www.qcisource.com/ihg/dist/img/blank.gif';
// Get image filesize for header
$filesize = filesize( 'blank.gif' );
// Image output
header( 'Pragma: public' );
header( 'Expires: 0' );
header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' );
header( 'Cache-Control: private',false );
header( 'Content-Disposition: attachment; filename="blank.gif"' );
header( 'Content-Transfer-Encoding: binary' );
header( 'Content-Length: '.$filesize );
readfile( $graphic_http );
?>