HTTP_REFERER to create a condition for loading js

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
IamBadAtThis
Forum Newbie
Posts: 1
Joined: Mon Jul 26, 2010 2:18 pm

HTTP_REFERER to create a condition for loading js

Post by IamBadAtThis »

Hi,
I'm trying to create a splash page type effect on a site I'm working on (I know splash pages are bad etc but I have my reasons), and basically I want to call the script that runs the splash page only if the visitor is coming to the index from an external website. That way if a visitor clicks "home" from an internal page the splash won't launch. I've been searching about and it seems like I can do this with php using $_SERVER['HTTP_REFERER'], but I'm brand new to php and after playing with it all afternoon can't seem to make it work.

The following code loads the script but it doesn't seem to care if the referring URL contains "mysite" and an error message appears at the top of the page reading:
"A PHP Error was encountered
Severity: Notice
Message: Undefined index: HTTP_REFERER
Filename:..."

Code: Select all

<?php
$referrer=$_SERVER['HTTP_REFERER'];
if(stristr($referrer, "mysite") == FALSE) {

echo '
<script type="text/javascript">
$(document).ready(function() {
             
                   $("#wrapper").hide();
	
	$("#imgContainer").npFullBgImg("/imgs/splash_image.jpg", {fadeInSpeed: 2000, center: true});	
	$("#logoContainer").fullLogoImg("/imgs/splash_logo.png", {fadeInSpeed: 2000, center: true});
	$("#logoContainer").click(function(){

		$("#wrapper").show("fast");
		$("#splash_kill").remove();
		$(this).remove();
		
	});
});
    </script>';
}
?>
Any help would be much appreciated. Thanks!
Post Reply