You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

73 lines
2.3 KiB

<?php
/**
* Created by xiaofu.qin
* email: xiaofu.qin@fanraun.com
* Date: 2017/3/2
* Time: 15:28
* Description: 在官网的首页引入执行main函数就可以设置相应的cookie,然后在需要跳转到登录/注册页面的页面下绑定dynamicPath.js下的那个函数就可以在登录和注册页面上接收线索来源这个信息了。
*/
/*
* 获取当前的url
* @return url
*/
function curPageURL(){
$pageURL = 'http://';
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
}
else {
$pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
}
return $pageURL;
}
/*
* 判断来源
*
* @return $flag: 线索来源字符串
* baidufr : 来自finereport百度推广
* baidufbi : 来自fineBI百度推广
* bbs : 来自bbs
* shop : 来自应用中心
* helpfr : 来自finereport帮助文档
* helpfbi : 来自fineBI帮助文档
* www : 来自直接输入finereport或者fineBI官网的访问
*/ function whereAreYouFrom() { $currentUrl = curPageURL(); try{ $prevPageUrl = $_SERVER['HTTP_REFERER']; }catch (Exception $err) { return 'Unknown'; } $flag = null; //首先判断是否来自于百度推广 if( strpos($currentUrl, 'bdtg') !== false ) { $flag = strpos($currentUrl, 'report') ? 'baidufr' : 'baidufbi'; } else { if( strpos($prevPageUrl, 'help') !== false ) { $flag = strpos($prevPageUrl, 'report')!== false ? 'helpfr' : 'helpfbi'; }else{ $array = array(); $pattern = '/\/\/([^\.]+)/'; preg_match_all($pattern, $prevPageUrl, $array); $flag = $array[1][0]; } } return $flag; } /* * 设置名为clueSource的cookie,首先判断是否已经设置,如果有就不会进行设置了 */ function main() { $flag = whereAreYouFrom(); if( !isset($_COOKIE['clueSource']) || $_COOKIE['clueSource'] == 'Unknown' ) { setcookie("clueSource", $flag, time()+3600); } }