Jump to content

[SOLVED] How to prevent the include content from being called independantly?


Recommended Posts

I am putting together a page made up of several pages using PHP, I am pretty new to PHP. My main page is listed below.

 

What I am afraid of is, search engines will only list one of the items that I am "including".

 

I have seen where cookies are used for passwords protected pages, to redirect to a login or other page. Is somthing along those lines, going to be the best way to ensure that if someone tries the www.xxxxxxx.com/body.php that it redirects to www.xxxxxxx.com/index.php, which will assemble the page properly with the ....body.php? The pages are not password protected.

 

If so how do I make the cookie expire, once the page completes loading?

 

I thought that it might be better to at the top of the page set a variable to a specific value, and then at the begining of each of the individual pages, look to see if the variable = specific value, if so continue, of not redirect, and at the end of the last page clear the variable? If this is possible, what would it be called so I can look it up, and learn or are there any examples I can look at?

 

index.php

 

<?php

define('IN_PHP', true);

$php_root_path = './';

include($php_root_path . 'extension.inc');

include($php_root_path . 'root.php'); /*?>for the meta and header part of the page<?php */

include($php_root_path . 'header.php'); /*?>for the header part of the page<?php */

include($php_root_path . 'nav.php'); /*?>for the navigation bar part of the page<?php */

include($php_root_path . 'body.php'); /*?>for the main body and content part of the page<?php */

include($php_root_path . 'footer.php'); /*?>for the footer part of the page<?php */

?>

 

So if I understand this correctly, this would go in the individual pages.

 

if (!defined("IN_PHP"))

 

this is asking if not "IN_PHP" then

 

{header("Location: index.php"); }

 

redirect to "index.php" else if "IN_PHP" then do everything else, correct?

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.