Re: uri/url help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 2008-12-26 at 22:02 -0800, Kenton P. Kammer wrote:
> I'm trying to make something to redirect people to my home page if they some how access my include pages.  For example, I have a generic copyright .htm with links in it that I add to all my pages with the include().  Problem is when I'm trying to make it the uri is always where it is in the include folder I made, even when I'm on the home page trying to view the links.  This is what I have:
> 
> <?
>   $uri=$_SERVER["REQUEST_URI"];
>   if($uri=='/'.strpbrk($uri, 'include')){header("Location: ../index.php");}
>   else{
> ?>
> <p>page content</p>
> <? } ?>
> 
> But the error is that since it always returns the /include/...htm uri even when I'm viewing it on http://www.domain.com/index.php
> 
> Help please! Thank you!

The most common way to do this (I think) is to define a variable in your
site's main config. In each include file test for it having been set. If
it is not set, then the file is being accessed improperly and so you
redirect.

For instance:

File: myConfig.php
------------------
<?php

    define( 'MY_CONFIG_LOADED', 1 );

?>

File: myClass.php
-----------------
<?php

    if( !defined( 'MY_CONFIG_LOADED' ) )
    {
        header( 'Location: http://www.foo.bar.nuh.uh.com/403.php' );
    }

?>

On a related note though... they probably shouldn't be able to dig
around your include directory in the first place. Better to deny those
requests via a webserver config (usually a .htaccess file).

Cheers,
Rob.       
-- 
http://www.interjinn.com
Application and Templating Framework for PHP


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux