Dynadot .com transfer sale, only $10.12 with coupon code DYNA12, available while supplies last, ends October 31, 2026.

[ PHP ] Track Refering Sites

NamecheapNamecheap
SpaceshipSpaceship
SpaceshipSpaceship
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
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
DomainEasy: flexible LTO options. Close more domain deals with financing.

We're social

Escrow.com
Spaceship
Escrowly
CryptoExchange.com
Domain Recover

NamePros updates

New in Parking: updated way to act on many domains or inquiries at once
Your domain list and inquiry list now have a bar above and below the list. Check the items you want, then choose an action in the bar...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back