skatermike21988 Posted July 15, 2006 Share Posted July 15, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/14662-quck-referrer-question/ Share on other sites More sharing options...
zq29 Posted July 15, 2006 Share Posted July 15, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/14662-quck-referrer-question/#findComment-58441 Share on other sites More sharing options...
ShogunWarrior Posted July 15, 2006 Share Posted July 15, 2006 Definitely, for speed you should use [b]cURL[/b] if possible and then scrape it as SA said. Quote Link to comment https://forums.phpfreaks.com/topic/14662-quck-referrer-question/#findComment-58442 Share on other sites More sharing options...
skatermike21988 Posted July 15, 2006 Author Share Posted July 15, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/14662-quck-referrer-question/#findComment-58443 Share on other sites More sharing options...
GingerRobot Posted July 15, 2006 Share Posted July 15, 2006 If the referring page is comming from a page you have control over you could pass the title through the url. Quote Link to comment https://forums.phpfreaks.com/topic/14662-quck-referrer-question/#findComment-58448 Share on other sites More sharing options...
skatermike21988 Posted July 15, 2006 Author Share Posted July 15, 2006 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-8have it display the title of the page. Quote Link to comment https://forums.phpfreaks.com/topic/14662-quck-referrer-question/#findComment-58449 Share on other sites More sharing options...
ShogunWarrior Posted July 15, 2006 Share Posted July 15, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/14662-quck-referrer-question/#findComment-58570 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.