Jump to content

PHP script to record email & IP address via email link


JudyO

Recommended Posts

Hi, n0obie here.  I'm trying to identify where my customers are coming from via emails I've sent/received. However, many email providers (namely Gmail) have circumvented this by disallowing IP address geolocation/image caching.

 

When potential customers click on the link in the email I sent them, it would direct them to an offer (page on my website). At the same time, the PHP script would be writing their details in the background to a log.txt file on my server.

 

I've figured out how to log their IP address (if they click on the link in the email sent), but need to tie it back to their email address so I know who's who. Being a PHP neophyte, I'm not sure how to code it for the email address parameter. 

 

Below is as far as I could get. Can someone puhleeeze help me out here?

 

--

<?php

$ip = $_SERVER['REMOTE_ADDR'];

$dt = date("l dS \of F Y h:i:s A");

$email = email

$file=fopen("ip_log.txt","a");

$data = $ip.' '.$dt."\n" $email.' ';

fwrite($file, $data);

fclose($file);

header( 'location http www myserverdotcom webpageofferdothtml' ) ;

?>

Edited by JudyO
Link to comment
Share on other sites

^^^yes, agreed!  Only problem is that I'm not sure of how to modify my script to track for those identifiers (already got the IP address part figured out).  Any ideas?  

 

e.g.:

 

     $email = email     (not sure if the syntax is right for this to capture the sender's email address)

Edited by JudyO
Link to comment
Share on other sites

You have to put the values in the URL. Like in the query string. A naive example would be

http://www.example.com/redir.php?email=alice@example.com&campaign=123&url=http%3A%2F%2Fwww.google.com
<a href="http://www.example.com/redir.php?email=alice@example.com&campaign=123&url=http%3A%2F%2Fwww.google.com">Google.com</a>
But that's blatantly obvious what it's for. I would go for something a bit more sophisticated: a table with the email campaign, email address, and a unique code. Like

id | campaign | email             | code     | count
---+----------+-------------------+----------+------
 1 |      123 | alice@example.com | vlw3igno |     0
 2 |      123 |   bob@example.com | 3sdfbghu |     0
http://www.example.com/redir.php?id=1&track=vlw3igno&url=http%3A%2F%2Fwww.google.com
To check for tampering you look up the id and tracking code and set count++ if they match a record. The code doesn't even have to be unique.
Link to comment
Share on other sites

Thanks so much, requinix!  That looks like it definitely would work; however, I still need to capture the IP address for geolocation purposes (hence using my original PHP script).  How would you suggest work that in here?  Incorporate that into the url (if possible) or try to run the script simultaneously?

Link to comment
Share on other sites

You get the value from $_SERVER. Like you're already doing. With $ip.

And then put it in the database like the other values (campaign/email/code/etc). When the person clicks the link and visits your site, retrieve the data from the db using the query string identifiers.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.