0

I have include "content.php" that loads in "index.php". How do I redirect the include to load into "index.php" when user requests direct URL access to "content.php"?

2
  • Some pseudocode illustrating your question, please. Commented Oct 11, 2011 at 13:13
  • You should accept an answer when you are satisfied ;) Commented Dec 2, 2014 at 11:56

3 Answers 3

3

You can set a constant in your index.php before your include content.php; then in content.php check if it's defined. If not redirect to index.php. Example:

<?php // index.php

define('IN_APP', true);

include 'content.php';

?>

<?php // content.php

if(!defined('IN_APP')){ 
    header('Location: index.php') 
}

?>
Sign up to request clarification or add additional context in comments.

Comments

0

At the top of your content.php:

if( strstr($_SERVER['REQUEST_URI'], 'index.php') != 0 ) {
    header('Location: index.php');
    exit;
}

Comments

0

You could use basename($_SERVER["SCRIPT_FILENAME"]) to find the name of the script currently being executed.

It will return the file name even if it is the index file and called with a url like this path/. $_SERVER['REQUEST_URI'] would return only /.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.