NameSilo

[ PHP ] Track Refering Sites

Namecheap AuctionsNamecheap Auctions
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
AIVikingsAIVikings

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back