GetGalax
GetGalax

Reputation: 149

HTTP_REFERER to location Iframe?

First of all, my php knowledge is equal to zero. But I've manage to find a script that check if the visitor is coming from a certain site and then redirects the visitor to another:

<?php 

$referer = $_SERVER['HTTP_REFERER']; 

if ($referer =   'http://www.facebook.com/') 
{ 
header('Location: http://www.test.com/facebook'); 
} 

else 
{ 
header('Location: http://www.test.com/failed'); 
} 

?>

But i was wondering If I can use this script on a page itself. So if a user is coming from i.e. Facebook he is directed to an iframe with content on the same page? Like "Location: iframe". Otherwise he's not allowed on the page and will get redirected.

Kind of like a gatekeeper ;)

Thanks in advance guys!

/a

Upvotes: 0

Views: 1307

Answers (2)

Steve
Steve

Reputation: 20469

Simply put the redirect at the top of the page: This reads "If visitor did NOT come from facebook, redirect them. If they did, show rest of page

<?php 

$referer = $_SERVER['HTTP_REFERER']; 

if (strpos($referer, 'www.facebook.com') === FALSE)
{ 
    header('Location: http://www.test.com/failed'); 
    exit();
} 


?>

<!DOCTYPE html>
<html lang="en">
<head>
    <!-- etc etc -->

Please note that referer headers can be faked, and are not guaranteed to be sent at all, depending on how the users browser is configured

Upvotes: 1

Universe
Universe

Reputation: 1

Use $_SESSION to check if he is authenticated to visit the site or not

Upvotes: 0

Related Questions