Jump to content

Quck referrer question


skatermike21988

Recommended Posts

As far as I know, the title isn't passed by the browser. You'd have to use the referer URL and scrape the page to pull out its title. You could use a combo of file() and eregi() for your scraping, if you're not too great with regular expressions, pop over to our Regex forum or give [url=http://www.regular-expressions.info]this site[/url] a look.
Link to comment
https://forums.phpfreaks.com/topic/14662-quck-referrer-question/#findComment-58441
Share on other sites

Well what i am doing is i have a visitor tracking system and instead of it displaying the long url (like you would get if you searched yahoo, or google etc) for it to display the page title. the way i have it is it logs the user's i.p. how many times they have visited last time they have visited and referrer. and underneath it i have the top ten referrers but displaying a long link like:

http://search.yahoo.com/search?p=thescreenguy&fr=FP-tab-web-t402&toggle=1&cop=&ei=UTF-8

have it display the title of the page.
Link to comment
https://forums.phpfreaks.com/topic/14662-quck-referrer-question/#findComment-58449
Share on other sites

This code will try and connect to the referring page and get the title.
It has several fallbacks so if the title is equal to (boolean) [b]false[/b] then you can use the URL.

[code]
<?php

$referer = ((isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER']!='')?($_SERVER['HTTP_REFERER']):(false));
$title = false;
if($referer!=false)
{
        $curl  = curl_init();
        CURL_SETOPT($curl,CURLOPT_URL,$referer);
        curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
        curl_setopt($curl,CURLOPT_FOLLOWLOCATION,0);
        curl_setopt($curl,CURLOPT_POST,0);
        $result = curl_exec($curl);
        if($result)
        {
                $res = preg_match('@<title.*?>(.*?)</title.*?>@',$result,$matches);
                if($res)
                {
                        $title = ((isset($matches[1]))?($matches[1]):(false));
                }
                else
                {
                        $title = false;
                }
        }
        else
        {
                $title = false;
        }
}
[/code]

Now, $title should be the title of the page, or [b]false[/b] if none was found.
Link to comment
https://forums.phpfreaks.com/topic/14662-quck-referrer-question/#findComment-58570
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.