public function home() { Linkserver_Client::init(SystemTool::getLinkServerHost(), ENV, SystemTool::getLinkServerUser(), SystemTool::getLinkServerPass()); //Ensure we are in a session SystemTool::ensureSession(); $url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; $http_referer = empty($_SERVER['HTTP_REFERER']) ? null : $_SERVER['HTTP_REFERER']; $http_user_agent = empty($_SERVER['HTTP_USER_AGENT']) ? null : $_SERVER['HTTP_USER_AGENT']; $url_cookie = parse_url($url); $host_parts = explode('.', $url_cookie['host']); $host_parts = array_reverse($host_parts); $this->cookie_host = '.' . $host_parts[1] . '.' . $host_parts[0]; $user_tracking_id = !empty($_COOKIE['user_tracking_id']) ? $_COOKIE['user_tracking_id'] : null; if (empty($user_tracking_id)) { $user_tracking_id = SystemTool::getGUID(); setcookie('user_tracking_id', $user_tracking_id, time() + 3600 * 24 * 365 * 20, '/', $this->cookie_host); } $_SESSION['user_tracking_id'] = $user_tracking_id; // new session tracking id if one does not exist if (empty($_SESSION["session_tracking_id"])) { $session_tracking_id = SystemTool::getGUID(); $_SESSION['session_tracking_id'] = $session_tracking_id; } else { $session_tracking_id = $_SESSION['session_tracking_id']; } // always new client tracking id after link click $client_tracking_id = SystemTool::getGUID(); $_SESSION["client_tracking_id"] = $client_tracking_id; // No account guid available $track_data = array("remote_addr" => $this->getRemoteIP(), "http_referer" => $http_referer, "user_agent" => $http_user_agent, "client_tracking_id" => $client_tracking_id, "session_tracking_id" => $session_tracking_id, "user_tracking_id" => $user_tracking_id); // call linkserever try { $result = LSC_Link::track_link($url, $track_data); } catch (Exception $e) { $message = $e->getMessage(); $full_stack = $e->getTraceAsString(); Notify::exception(__FILE__, $message, $full_stack, array('result' => $result, 'track_date' => $track_data)); header("Location: http://" . $_SERVER['SERVER_NAME'], TRUE, 307); exit; } // No matching Host record Fowarding to index page of this site if (empty($result)) { // bad link $url_parts = parse_url($url); $url2 = 'http://' . $url_parts['host']; $message = "No matching Host record. Posted url: {$url} <br />Forwarding to Url: {$url2} <br />"; $trace = print_r($result, true); $this->send_exception(__FILE__, $message, $trace); header("Location: " . $url2, TRUE, 307); exit; } else { // Correct Link if (!empty($result["id"])) { // we found the link $url_parts = parse_url($result["url"]); // use peer redirect because we are at the wrong casey site if (!empty($result["peer_redirect"])) { header("Location: " . $result["peer_redirect"], TRUE, 301); exit; } if (isset($result["property_code"]) && strlen($result["property_code"]) > 2) { $ppref = strtoupper(substr($result["property_code"], 0, 3)) . "999" . "ZZ" . "9999" . "Z"; //fix made 3/6/13 $_SESSION["ppref"] = $ppref; } $forward_url = $result["url"]; $header_code = 301; } else { //we did find the link but keep session handling $header_code = 307; $forward_url = "http://" . $_SERVER['SERVER_NAME']; } $this->set_affiliate($result); header("Location: " . $forward_url, TRUE, $header_code); exit; } }