Tracking Email when they Click Using PHP

456 views Asked by At

I am in need of a some help if possible. What I want to do is: Send Newsletter, then I want to Track who "clicked on the ads" and auto link to the website URL.

This is what I have so far:

<?php
if( $_GET["email"]) { echo $_GET["email"];}
$email = $_GET["email"];
$page = $_GET["page"];
mysql_connect("localhost", "dbname", "password") or die(mysql_error());
mysql_select_db("dbname") or die(mysql_error());
$redirect = mysql_real_escape_string($_GET['page']);
$page_insert = mysql_query("INSERT INTO tracking_table (`email`, `rec_use_date`) VALUES ('$email', now())") or die(mysql_error());
header("Location:$redirect");exit; 
?>

What I have will save to the database, but won't redirect to the URL:

http://www.malaysiastreet.com/tracking/[email protected]&page=http://www.google.com
2

There are 2 answers

3
Bruce On

Use base64_decode($_GET["return_url"]); to get the URl of the user..

Use this code...

<?php

$return_url = base64_decode($_GET["return_url"]); //return url

if( $_GET["email"]) { echo $_GET["email"];}
$email = $_GET["email"];
$page = $_GET["page"];
mysql_connect("localhost", "dbname", "password") or die(mysql_error());
mysql_select_db("dbname") or die(mysql_error());
$redirect = mysql_real_escape_string($_GET['page']);
$page_insert = mysql_query("INSERT INTO tracking_table (`email`, `rec_use_date`) VALUES ('$email', now())") or die(mysql_error());
//to return the user URl
header('Location:'.$return_url);
?>
1
dstudeba On

Please try a space after the :

change

header("Location:$redirect");

to

header("Location: " . $redirect);

Also when you put on the website please use mysqli_ instead of mysql_