phpredirect-loop

Fix a redirect loop?


I have the following code in my index.php page:

 <?php include("/includes/widgets.php") ?>

And in my widgets.php page:

<?php
     header("Location: /");
?>

What I want to achieve with this is to redirect it if the user visits it, but allow it for including.

But I get the following error:

The webpage has a redirect loop

How can I fix/prevent the redirect loop, but still redirect the user and not the server.


Solution

  • Place the widgets.php file in a folder not accessible to HTTP clients. I.e on apache webserver, either put it above your document root (into it's parent) or use .htaccess file to block users from it.

    e.g.

    deny from all