Capturing Click Data: "Capturing Click Data
Capturing click data is useful when you want to look at trends such as pages that are looked at the most, or amount of traffic.
To do this you would need to call the function below each time a page is loaded to capture the click data such as user ip, page title and url. Ofcourse you can capture more info here, for example date.
Further on you would need to save the click data in a database or text file (for example a csv file ready to be viewed in excel).
function saveClickData($pageTitle){
//try and get the ip of the client.
$ip ='';
if ( isset($_SERVER['REMOTE_ADDR']) ) {
$ip = '' . $_SERVER['REMOTE_ADDR'] . ' ';
} else if ( isset($_SERVER['HTTP_X_FORWARDED_FOR']) ) {
$ip = '' . $_SERVER['HTTP_X_FORWARDED_FOR'] . ' ';
} else if ( isset($_SERVER['HTTP_CLIENT_IP']) ) {
$ip = '' . $_SERVER['HTTP_CLIENT_IP'] . ' ';
}
$link = $_SERVER['PHP_SELF'].$_SERVER['QUERY_STRING'];
}"
martedì 10 novembre 2009
SEO URLs with PHP
SEO URLs with PHP: "SEO URLs with PHP"
Do you want to implement your own search friendly url engine? Limeware has its own URL rewrite engine which is not dependent on Apache mod_rewrite. It is relatively easy to implement in other systems or to adapt to your specs.This is an evil url: www.notfriendly.com/index.php?menuID=28&type=articleThis is a good url: www.friendly.com/index/menuID_28-type_articleMy solution in Limeware CMS is to do the URL processing in PHP. If you follow these steps you will have your own Apache compatible URL rewrite engine in no time.Step 1.In your .htaccess file (If you don't have one, then create a new one in the folder where your index.php resides) add the following:
ForceType application/x-httpd-php This simply tells your apache server to treat "index" in the url as "index.php". If you are using a server other than apache, then you will need to configure it to do this.Step 2.Implement the class below so that an instance is create each time index.php is executed. What this does is it takes the special url www.friendly.com/index/menuID_28-type_article andsplits it into www.friendly.com/index/ and menuID_28-type_article strings, then it creates an array:array['menuID'] = 28array['type'] = articleYou cannot use $_GET['paramName'], instead call getItem($key) method in UrlFilter passing the name of the parameter you want, for exaple: $this->urlFilter -> getItem("menuID").You can use any number of parameters, and name them as you wish, all you have to do is use the getItem() method and you got yourself nice URLs. Ofcourse you will need to build your links correctly for this to work, use getOriginalUrl() for this, then add your parameters to it: /param_value-param2_value2-param3_value3 and so on...
// constructs search friendly urls and create correct url paths for links and imagesclass UrlFilter { var $origUrl; var $numOfItems; var $itemsMap; function UrlFilter() { $this->processURI(); $this->constructBaseUrl(); } function processURI() { $array = explode("index", $_SERVER['PHP_SELF']); $newUrl = str_replace("/", "", $array[count($array)-1]); $array = explode("-", $newUrl); $num = count($array); $this->numOfItems = $num; $url_array = array(); $items = explode("-", $newUrl); $num = count($items); for ($i = 0 ; $i < $num ; $i++) { $item = explode("_", $items[$i]); $this->itemsMap[$item[0]] = $item[1] ; } } function constructBaseUrl() { // need to construct the original url $array = explode("index", $_SERVER['PHP_SELF']); $num = count($array); $this->origUrl = ""; for ($i = 0; $i < $num-1 ; $i++) { $this->origUrl = $this->origUrl . $array[$i]; } } function getItem($key) { if (array_key_exists($key, $this->itemsMap)) { return $this->itemsMap[$key]; } else { return null; } } function getOriginalUrl() { return $this->origUrl . "index"; } function getBaseUrl() { return $this->origUrl; }}
Do you want to implement your own search friendly url engine? Limeware has its own URL rewrite engine which is not dependent on Apache mod_rewrite. It is relatively easy to implement in other systems or to adapt to your specs.This is an evil url: www.notfriendly.com/index.php?menuID=28&type=articleThis is a good url: www.friendly.com/index/menuID_28-type_articleMy solution in Limeware CMS is to do the URL processing in PHP. If you follow these steps you will have your own Apache compatible URL rewrite engine in no time.Step 1.In your .htaccess file (If you don't have one, then create a new one in the folder where your index.php resides) add the following:
// constructs search friendly urls and create correct url paths for links and imagesclass UrlFilter { var $origUrl; var $numOfItems; var $itemsMap; function UrlFilter() { $this->processURI(); $this->constructBaseUrl(); } function processURI() { $array = explode("index", $_SERVER['PHP_SELF']); $newUrl = str_replace("/", "", $array[count($array)-1]); $array = explode("-", $newUrl); $num = count($array); $this->numOfItems = $num; $url_array = array(); $items = explode("-", $newUrl); $num = count($items); for ($i = 0 ; $i < $num ; $i++) { $item = explode("_", $items[$i]); $this->itemsMap[$item[0]] = $item[1] ; } } function constructBaseUrl() { // need to construct the original url $array = explode("index", $_SERVER['PHP_SELF']); $num = count($array); $this->origUrl = ""; for ($i = 0; $i < $num-1 ; $i++) { $this->origUrl = $this->origUrl . $array[$i]; } } function getItem($key) { if (array_key_exists($key, $this->itemsMap)) { return $this->itemsMap[$key]; } else { return null; } } function getOriginalUrl() { return $this->origUrl . "index"; } function getBaseUrl() { return $this->origUrl; }}
Iscriviti a:
Post (Atom)