Cool Referring URL Script Not Working

by 6 replies
7
This is frustrating

The below is a awesome script I've put together with a coding friend used for tracking form submissions. If the person came from a Google, MSN, or Yahoo search, it inserts the searched keywords. If the person came from another source, it inserts the URL.

Whenever I test it I look in the source code and it inserts properly! But 8 of 9 submissions since I put it up have returned "No search term or referring URL", which should only be the case if they type in the url directly or bookmark the site - extremely, extremely unlikely.

You can test it and see the site at recruitshop.com.au

<input type="hidden" mandatory="false" validation="" sf_title="Search Term" value="<?php echo ReferringSourceLarge(); ?>">

Code:
<?php
function ReferringSourceLarge()
{
$refer = parse_url($_SERVER['HTTP_REFERER']);
$host = $refer['host'];
if($host != 'www.recruitshop.com.au' && $host != 'recruitshop.com.au') {
	$querycal = $refer['query'];
	$_SESSION['query'] = explode("&", $querycal);
	$_SESSION['extrefer'] = $_SERVER['HTTP_REFERER'];
}
if (isset($_SESSION['query'])) {
	foreach($_SESSION['query'] as $q)
	{
		list($key, $value) = explode("=", $q);
		$a[$key] = urldecode($value);
	}
}
if(!isset($_SESSION['extrefer'])) return 'No search term or referring URL';
if(strstr($host,'google'))
{
	$_SESSION['a'] = $a['q'];
	return $_SESSION['a'];
}
elseif(strstr($host,'yahoo'))
{
	$_SESSION['a'] = $a['p'];
	return $_SESSION['a'];
}
elseif(strstr($host,'msn'))
{
	$_SESSION['a'] = $a['q'];
	return $_SESSION['a'];
}
else if (isset($_SESSION['a']))
{
	return $_SESSION['a'];
}
else { return $_SESSION['extrefer']; }
}
?>
If you can't solve it, any direction would be greatly appreciated!
#programming #cool #referring #script #url #working
  • [DELETED]
  • Do you have
    Code:
    <?php session_start(); ?>
    at the beginning of the page?

    Without it session variables won't work. It has to be on every page that uses sessions.
    • [1] reply
    • I doubt it's a database error because it hasn't been working over a month's time.

      Yes.
  • This could also be because HTTP_REFERER isn't always passed by the user's browser.
    • [1] reply
    • Isn't always? What, are there certain browsers that reject this session variable?

      What's something more reliable then Mogul Sir?
      • [1] reply

Next Topics on Trending Feed

  • 7

    This is frustrating The below is a awesome script I've put together with a coding friend used for tracking form submissions. If the person came from a Google, MSN, or Yahoo search, it inserts the searched keywords. If the person came from another source, it inserts the URL.