[Phplogcon-dev] duplicated code

Brian Shea bgshea at gmail.com
Wed Dec 7 17:00:33 CET 2005


Can't, unless certain varibles are passed becuse the code looks at the file
the code is in, and sometimes I need

header("Location: ../index.php");

or

header("Location: index.php");

Look close, one has ../index.php the other does not.

I've always just seen it place at the top of every file as needed.

On 12/7/05, Michael Meckelein <mmeckelein at hq.adiscon.com> wrote:
>
> Hi Brian,
>
> I noticed that you use duplicated code in some files. The code snippet
> below is in e.g.  auth.php, config.php, include.php, ...
>
> Wouldn't it be better to put it into a function onto the top in
> include.php?
>
> // BGS -- This will remove the trailin / in a uri like .../index.php/
> // This causes the directories to get mucked up.
> // Patch from http://www.php.net/manual/en/ref.apache.php by
> henk_nicolai at REMOVE-THIS at hotmail dot com
>         $req = $_SERVER['REQUEST_URI'];
>         // Remove rubbish.
>         $newReq = ereg_replace ( $_SERVER['SCRIPT_NAME'] . '[^?]*',
> $_SERVER['SCRIPT_NAME'], $req);
>         if (strlen($newReq) < strlen($req))
>         {
>                 header ('Location: '.$newReq);
>                 header ('HTTP/1.0 301 Moved Permanently');
>                 die;  // Don't send any more output.
>         }
>         unset($req);
>         unset($newReq);
> // BGS end
> // BGS -- do not all access from URI
> $filename =  substr(__FILE__, strrpos( __FILE__, "/" ));
> $requestname = substr($_SERVER['SCRIPT_NAME'], strrpos(
> $_SERVER['SCRIPT_NAME'], "/" ));
> if( $filename == $requestname )
> {
>         session_unset();
>         header("Location: ../index.php");
>         exit;
> }
> // BGS end
>
> Michael
> _______________________________________________
> Phplogcon-dev mailing list
> http://lists.adiscon.net/mailman/listinfo/phplogcon-dev
>



More information about the Phplogcon-dev mailing list