Jump to content


Photo

Quck referrer question


  • Please log in to reply
6 replies to this topic

#1 skatermike21988

skatermike21988
  • Members
  • PipPipPip
  • Advanced Member
  • 100 posts
  • LocationFlorida

Posted 15 July 2006 - 09:08 AM

Hey guys,

i am just curious to know if there is a way to get the title of a refering page.

i am currently useing @$HTTP_REFERER to recieve the link and was wondering about recieving the title.

thanks for any help.


#2 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 15 July 2006 - 09:13 AM

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 this site a look.

#3 ShogunWarrior

ShogunWarrior
  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 15 July 2006 - 09:14 AM

Definitely, for speed you should use cURL if possible and then scrape it as SA said.
<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd

#4 skatermike21988

skatermike21988
  • Members
  • PipPipPip
  • Advanced Member
  • 100 posts
  • LocationFlorida

Posted 15 July 2006 - 09:18 AM

ok how would i go abou cURL and the scrapeing with regex i am relatively new to php and am really trying hard to learn this stuff.

#5 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 15 July 2006 - 09:35 AM

If the referring page is comming from a page you have control over you could pass the title through the url.

#6 skatermike21988

skatermike21988
  • Members
  • PipPipPip
  • Advanced Member
  • 100 posts
  • LocationFlorida

Posted 15 July 2006 - 09:40 AM

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....1&cop=&ei=UTF-8

have it display the title of the page.

#7 ShogunWarrior

ShogunWarrior
  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 15 July 2006 - 05:18 PM

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) false then you can use the URL.

<?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;
        }
}

Now, $title should be the title of the page, or false if none was found.
<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users