Search code examples
phpparent

php - how to redirect if parent


There is an iframe on my index page that is not suposed to be viewed outside of that parent page.

So if the iframe isnt being viewed on the parent page http://mysite.com/index.php it should be redirected to http://mysite.com/

Im thinking of something like:

if ($_SERVER['REQUEST_URI'] !== 'http://mysite.com/') {
    include_once 'http://mysite.com/';
}

Solution

  • I would do it similarly to your approach:

    if ($_SERVER['HTTP_HOST'] !== 'mysite.com') {
       header("Location: mysite.com");
    }
    

    if you need it for just your index page then

    if ($_SERVER['HTTP_HOST'] !== 'mysite.com' && $_SERVER['REQUEST_URI']!=='index.php') {
       header("Location: mysite.com");
    }