Stop Php Execute in page [duplicate]

You can use $_SERVER[‘HTTP_REFERER’] to make sure that the refering page (previous page) was the one that you expect:

<?php 
// if the request comes from a file that contains the string "conforming.php" then render the page
    if(stristr($_SERVER['HTTP_REFERER'], "conforming.php")) {
         //serve page if came from conforming.php
     }
// if the referring page is not conforming.php, then redirect the user to the conforming version
    else  {
        header("Location: conforming.php");
    }
?>

additional information: https://www.w3.org/TR/WCAG20-TECHS/SVR3.html

EDIT** I customized the code below according to your additional requirements:

<?php 

if (stristr($_SERVER['HTTP_REFERER'], "https://Domain1.com/away.php"))
{
    if (isset($_GET['id2']))
    {
        $id2 = $_GET['id2'];
        echo "<iframe frameborder=\"0\" scrolling=\"no\" width=\"560\" height=\"320\" src=\"https://www.xxxxxxxxxx.com/files.php?v=$id2\" allowfullscreen=\"true\" webkitallowfullscreen=\"true\" mozallowfullscreen=\"true\" ></iframe>";
    } else{
        echo "id is empty";
    }
    
}
else
{
    //invalid referer! go back to domain1 to make it valid!
    header("Location: https://Domain2.com/xxxxxxxx/");
}

?>

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top