0
votes

I have come up with the following solution:

CREATE TABLE logger ( id int(11) NOT NULL AUTO_INCREMENT, ip int(11) NOT NULL, landing varchar(16) DEFAULT NULL, updated timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=latin1

See if entry exists select id, landing from logger where ip = INET_ATON('10.0.5.9') and updated > date_add(CURRENT_TIMESTAMP,interval -2 DAY) order by id desc limit 1;

If exists update. This shall automatically update the updated field update logger set landing = 'landing' where id = 1;

If not exist add the entry insert into logger (ip, landing) value (INET_ATON('10.0.5.9'), '/');

Could anyone help me with the php bits to add into my headers as i have successfully sorted the MySQL bits now.

Thanks in advance guys!

2
The answer is probably sessions / cookies. This is simple, with built in php functions. But what happends if they visit the url on the business card, then see the TV advert and follow that url? What homepage do they see? - Steve
Its very easy to collect the IP and drop a cookie but if you already know where the user is coming from then why not pass the soucce in the url as a parameter and then drop a cookie based on the source? IP's are no more reliable - Hanky Panky
Have you tried anything yet? Cookies are easy to set up, and you can set them on the first visit, and read them on the second visit etc. (Using an if statement or something similar). Using the global variable $_SERVER['REMOTE_ADDR'] you can get a user's IP. I wouldn't suggest using IP's for this, since they can easily be changed or shared. Maybe read how the user got on the page, then set a cookie based on that? - BananaMan

2 Answers

2
votes

A good solution would be to use a special URL that you would link to from email campaigns, where the "real" adress is added as query parameter:

Example which would redirect to http://example.com/foo http://example.com/campaign.php?forward_to=http%3A%2F%2Fexample.com%2Ffoo&campaign=bar

In that script you set a cookie and forward to the actual address

<?php 
   setcookie('campaign', $_GET['campaign']);
   header('Location: ' + $_GET['forward_to']);  
?>

Note that this script needs to be on the same domain. You could also do this without a redirect by just setting up a hook in functions.php and looking for a campaign query sting parameter and serving different stylesheets based on that. Example:

(this assumes that you have campaign specific stylesheets located in mytheme/styles/ named campaign-1.css, campaign-2.css )

// in /functions.php

/**
* Sets cookie if 'campaign' var is passed in url
*/
function get_campaign_code($query_vars) {
    if (isset($query_vars['campaign'])) {
        setcookie('campaign_code', $query_vars['campaign']);
    }
}

add_filter('query_vars', 'get_campaign_code');

/**
* Enqueue a campaign specific stylesheet if $_COOKIE['campaign_code'] is available
*/
function enqueue_campaign_stylesheet() {

    $cid = $_COOKIE['campaign_code'];

    if ( $_COOKIE['campaign_code'] ) {
         // creates uri to campaign specific  
         $src = sprintf('%s/styles/campaign-%d.css', 
                    get_template_directory_uri(),
                    $cid
                    );
         wp_enqueue_style( 'campaign_css', $src);
    }  
}

add_action( 'after_setup_theme', 'function_name');
1
votes

You should not use the ip to identify an user, use sessions instead (that is, use the cookie)

<?php
session_start();

//Set the correct page if not set already
if(!isset($_SESSION['page']){
  if(userCameFromEmail)
    $_SESSION['page'] = "someUrl1";
  else if(userCameFromTV)
    $_SESSION['page'] = "someUrl2";
  else if(userCameFromCard)
    $_SESSION['page'] = "someUrl3";
}

//Redirect
header("Location: " . $_SESSION['page']);

?>

This way the user will see the same page he saw the first time as long as he keeps the cookie. Keep present that this doesn't forbid access to the other urls. If you wan't to restrict access that's more difficult. You could add a different random code in each of your business cards, and ask for it in the page. Same goes for the email. The TV page is by definition public I guess you don't want to restrict access to it.