1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

PHP script to record IP, email, OS, browser via email link

Discussion in 'Black Hat SEO Tools' started by JudyO, Jan 1, 2015.

  1. JudyO

    JudyO Newbie

    Joined:
    Dec 3, 2011
    Messages:
    9
    Likes Received:
    0
    Occupation:
    Nomadic "consultant"
    Location:
    Wherever you pay me to be...
    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 geolocation/caching.

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

    I've figured out how to log their IP address (if they click on the email sent), but would like to tie it back to their email address, OS & browser as well. Being a PHP neophyte, I'm not sure how to code it for those parameters.


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


    --
    <?php
    $ip = $_SERVER['REMOTE_ADDR'];
    $dt = date("l dS \of F Y h:i:s A");
    $email = email
    $os = os
    $browser = browser

    $file=fopen("ip_log.txt","a");
    $data = $ip.' '.$dt."\n" $email.' ' $os ' ' $browser ' ';
    fwrite($file, $data);
    fclose($file);
    header( 'location http www myserverdotcom webpageofferdothtml' ) ;
    ?>
     
  2. Hinkys

    Hinkys Jr. VIP Jr. VIP

    Joined:
    Mar 3, 2012
    Messages:
    697
    Likes Received:
    553
    Location:
    Croatia
    This should let you pull both browser and OS info (pasted from php.net)

    PHP:
    <?php
    echo $_SERVER['HTTP_USER_AGENT'] . "\n\n";

    $browser get_browser(nulltrue);
    print_r($browser);
    ?>


    As far as emails go, only way I can think of is to somehow embedd user's email account in the link's query string (MAYBE possible if you're using some autoresponder service that supports personalization tags like [[name]], [], etc but I don't really see this working in real world).

    Depending on what you're trying to do, your best bet simply asking the user to input their email on the order page in exchange for a free report or whatever.

    [I]PS: I found the above code in 10 seconds, google is your friend.[/I]
     
    Last edited: Jan 1, 2015
  3. emild331

    emild331 Registered Member

    Joined:
    Dec 12, 2014
    Messages:
    60
    Likes Received:
    4
    Correct, go for making each link unique (by simply adding a parameter to the url) to tie the visitor with the link pressed - where you should then end up with email, browser, IP and OS. How to get the location is on the other hand a bit harder, the closest you get is getting location data from their IP which won't be very accurate, or you'll have to use a third party service as Google Maps Geolocation - but the user has to allow it to get your location.
     
  4. JudyO

    JudyO Newbie

    Joined:
    Dec 3, 2011
    Messages:
    9
    Likes Received:
    0
    Occupation:
    Nomadic "consultant"
    Location:
    Wherever you pay me to be...
    Thanks so much, Hinkys, I'm almost all the way there, now! Yes, it's going to be absolutely necessary that I tie back all of this info to the user's email address. Asking the user to input their email address is just not going to work in this case -- getting them to click on the link is going to be hard enough!

    I'm trying to do this all through a PHP script in order to avoid using an autoresponder (already thought of that). Hope that it's doable, though.
     
  5. emild331

    emild331 Registered Member

    Joined:
    Dec 12, 2014
    Messages:
    60
    Likes Received:
    4
    Are you mass-sending? I understand your original task was getting to know your visitors, although one approach (if mass-sending to thousands and thousands) would be to embed an iframe with the email. Not many clients support this (check link at bottom), but those that does can be of value as you later on can send them more targeted offers(that's what you're doing right?) and they might be more likely to press the link.

    Too low postcount, but here's the link which clients does and does not support iframes:

    campaignmonitor.com/blog/post/3219/do-iframes-work-in-email/
     
  6. JudyO

    JudyO Newbie

    Joined:
    Dec 3, 2011
    Messages:
    9
    Likes Received:
    0
    Occupation:
    Nomadic "consultant"
    Location:
    Wherever you pay me to be...
    No, this isn't going to be a mass mailing. More to the point it will be one-off emails that will be sent in response to an inquiry.

    Due to the fact that most of the emails received provide little identifying information, I'm trying to at least find out the general location via IP address tied to their email address via reverse engineering. I used to be able to find this info out via ReadNotify, but when Google disallowed geolocation a while back, this screwed the pooch so to speak.

    So, I'm back to Hinkys original suggestion to find out a way to do this by somehow embedding the user's email address in the PHP query. Any ideas?
     
  7. emild331

    emild331 Registered Member

    Joined:
    Dec 12, 2014
    Messages:
    60
    Likes Received:
    4
    You could just add a parameter to the URL, no?

    Say you're looping through the email list, when forming the body add a "?user=the_email" at the end of the URL they will be clicking.

    Then at the landingpage, check if $_GET[name] is set - and if so you know what emailaddress clicked the link.
     
  8. m4dm4n

    m4dm4n Regular Member

    Joined:
    Sep 15, 2010
    Messages:
    223
    Likes Received:
    92
    Occupation:
    /dev/full
    Location:
    /dev/urandom
    The easiest way i know to do this is to make the link contain all of the information you don't get directly like ip/browser.

    Something like http://example.com/some/path/?somequery&anotherquery&email={insert user email here}&name={insert user name here}

    The only issue with this is that users can then put any information there.

    The way to get around this is to have a database table:

    table users: id, name, email
    content:
    1, John, [email protected]
    2, Jane, [email protected]

    and send your emails with links like http://example.com/some/path/?somequery&anotherquery&id={insert user id here}

    and then you can do a simple database match based on the id to see who clicked the link.

    Email marketing software do something like this but a bit more complicated.
     
  9. JudyO

    JudyO Newbie

    Joined:
    Dec 3, 2011
    Messages:
    9
    Likes Received:
    0
    Occupation:
    Nomadic "consultant"
    Location:
    Wherever you pay me to be...
    Yes, that might be possible, but I will still have to correlate the email address with the IP and other parameters. Best to try to wrap this all in one script if possible...
     
  10. JudyO

    JudyO Newbie

    Joined:
    Dec 3, 2011
    Messages:
    9
    Likes Received:
    0
    Occupation:
    Nomadic "consultant"
    Location:
    Wherever you pay me to be...
    I'll see if I can get that to work but I'm such a coding neophyte that it probably would be easier to buy email marketing software! Will see if I can test something out with the url, but how would I go about creating a db table?
     
  11. Hinkys

    Hinkys Jr. VIP Jr. VIP

    Joined:
    Mar 3, 2012
    Messages:
    697
    Likes Received:
    553
    Location:
    Croatia
    http://teamtreehouse.com/library/using-php-with-mysql

    Get a free trial account and go through this tutorial, it's really begginer friendly and should cover everything you need to know about databases and php. That site also has alot of other useful coding tutorials, it's how I started with PHP and it beats DIY approach at learning basics of any langauge.
     
  12. JudyO

    JudyO Newbie

    Joined:
    Dec 3, 2011
    Messages:
    9
    Likes Received:
    0
    Occupation:
    Nomadic "consultant"
    Location:
    Wherever you pay me to be...
    Thanks a lot, Hinkys! Will take a look at the site to see if I can figure out how to make this work in PHP. Want to avoid subscribing to an email marketing system at all costs and host everything myself. Tx again!
     
  13. yenerich

    yenerich Jr. VIP Jr. VIP

    Joined:
    May 26, 2013
    Messages:
    1,182
    Likes Received:
    185
    Home Page:
    Your email can have some javascript that catch all this info for you.
    You can easily call some image with all the parameters, so all the info get into a php (that send the image and catch the info).
    This image can be a 1 pixel one, so its very fast to load.


    OR check this one (i have no connection with them)

    http://www.tracemyip.org/tools/show-user-ip-info-box/

    Specially the user interface at the bottom of the page.
     
    Last edited: Jan 4, 2015
  14. abda53

    abda53 Newbie

    Joined:
    May 14, 2010
    Messages:
    11
    Likes Received:
    2
    This will not work for what you are needing and you can not have javascript in it