NameSilo

[ PHP ] Track Refering Sites

SpaceshipSpaceship
SpaceshipSpaceship
NamecheapNamecheap
Watch

Ray

VIP Member
Impact
167
Below is a useful script that I wrote earlier today. Use it to track refering sites and insert them into the database when the user signs up. Basic PHP Knowledge Required



anypage.php
PHP:
<?php

if (isset($_SERVER['HTTP_REFERER'])) {     // check if there was a referrer

	$uri = parse_url($_SERVER['HTTP_REFERER']); 

	if($uri['host'] != "yourdomain.com"){          //Replace with your domain
	    $onvisit = $_SERVER['HTTP_REFERER']; //example www.mail.com/iamatest.php?test=true
	    $onvisitshort = $uri['host']; //example www.mail.com

	     if (empty( $_COOKIE['refererlong'])){  // checks to see if cookie exists, if not sets one
	         setcookie ("refererlong", $onvisit, time()+2592000, "/");  //sets for 30 days
	         setcookie ("referershort", $onvisitshort, time()+2592000, "/");  // sets for 30 days
	     } 
	}
}

?>

Insert the below code into your signup script to insert into a database.

signup.php
PHP:
<?php
$refererlong = $_COOKIE['refererlong']; // calls long url referer cookie
$referershort = $_COOKIE['referershort']; // calls short url referer cookie

//MySQL Insert Query Goes Here

?>
 
Last edited:
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
CatchedCatched

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Filters for activity feeds
Your news feed, Latest activity, and the activity tab on profiles now have filter buttons: All, Posts, Quick replies, and Other. Your...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back