JudyO Posted January 3, 2015 Share Posted January 3, 2015 (edited) 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 January 3, 2015 by JudyO Quote Link to comment Share on other sites More sharing options...
requinix Posted January 4, 2015 Share Posted January 4, 2015 You have to put the email address into the link they click, or else some kind of identifier that you relate to their email address (eg, random code or ID number). 1 Quote Link to comment Share on other sites More sharing options...
requinix Posted January 4, 2015 Share Posted January 4, 2015 Oh, and you should track which email they came from too. So that's two identifiers. Quote Link to comment Share on other sites More sharing options...
JudyO Posted January 4, 2015 Author Share Posted January 4, 2015 (edited) ^^^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 January 4, 2015 by JudyO Quote Link to comment Share on other sites More sharing options...
requinix Posted January 4, 2015 Share Posted January 4, 2015 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.comTo 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. Quote Link to comment Share on other sites More sharing options...
JudyO Posted January 4, 2015 Author Share Posted January 4, 2015 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? Quote Link to comment Share on other sites More sharing options...
requinix Posted January 4, 2015 Share Posted January 4, 2015 You get the value from $_SERVER. Like you're already doing. With $ip. Quote Link to comment Share on other sites More sharing options...
CroNiX Posted January 4, 2015 Share Posted January 4, 2015 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. Quote Link to comment Share on other sites More sharing options...
JudyO Posted January 4, 2015 Author Share Posted January 4, 2015 I'm a bit embarrassed to admit it, but what would you suggest for the db? SQL? Thanks so much for all the suggestions -- I'm not trying to be lazy, but I'm definitely not a coder... LOL. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.