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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.