http referer from specific URL

Good afternoon everyone. I borrowed this code from another site. I hope that wasn’t illegal. Anyway, I want to check to see where a certain page is being accessed from and if it isn’t from one specific page then I want to redirect to that specific page. I got the below for checking on where the person is coming from but how do I make them go back to that specific page. For instance they try to access http://domain.com/page1.html from somewhere else by direct linking to it, instead of coming from http://domain.com/page.html. How do I redirect them back to http://domain.com/page.html to force entry from that page? There is nothing being protected or anything I don’t want seen. I want to force them to read something and agree to it before accessing page1.html

Any help is appreciated!

<?php
// This is to check if the request is coming from a specific URL
$ref = $_SERVER['HTTP_REFERER'];

if($ref !== 'http://domain.com/page.html') {
  die("Hotlinking not permitted");
}

echo "Executing code here";
?>

a refer may not always exist instead how I would tackle this is change all .html pages to .php pages and use a session to check if the checkbox has been checked otherwise redirect the user back.

[php]

<?php session_start(); if ($_SESSION['hasChecked'] == false) { header('Location: Url/To/Redirect/Them/To'); exit(); } //rest of the page [/php] I would have that as an include in all other pages. Then on the entry page have a checkbox has been checked create a session called hasChecked with a value of true then redirect to the next page. For the refer route check if exists: [php]$ref = (isset($_SERVER['HTTP_REFERER'])) ? $_SERVER['HTTP_REFERER'] : null); if ($ref != 'http://domain.com/page.html') { header('Location: http://domain.com/page.html.'); exit(); }[/php]

Make the other page not exist.

If you are really adamant, include a token that needs to be there to keep api’s from pulling data too.

[php]
if($_POST[‘checked’] && $_POST[‘token’] == $token ){
// include the page they want to see
} else {
// include the start page
}

[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service