[Phplogcon-dev] duplicated code

Brian Shea bgshea at gmail.com
Wed Dec 7 17:13:36 CET 2005


Got it,sudo code is fine.

Wont work like that with out __FILE__

You need to pass the __FILE__ (special varible in php to give the file name)


so

checker(__FILE__, $wheretogo);

or no functions in notToBeCalled.php and just set

$me = __FILE__;
$wheretogo="home_sweet_home";
include notToBeCalled.php

//will get here if all is good.
unset($me);
unset($wheretogo);


The first trailing '/' can be a function. Nothing special there.

On 12/7/05, Rainer Gerhards <rgerhards at hq.adiscon.com> wrote:
>
> another php-noob suggestion...
>
> what if that function would be place in *another* include file that is
> included in the not-to-be-directly called pages. Then, that function
> could be passed in the proper redirect location.
>
> Let me use a sample, NOT in php (pseudo-php at best ;))
>
> in notToBeCalled.php
>   include check.php
>   call checker("../index.php")
>
> in check.php
>    checker(redirect)
>     do checking
>     redirect to "redirect" in case of error
>
> I hope this conveys what I intend to say...
>
> Rainer
>
> > -----Original Message-----
> > From: phplogcon-dev-bounces at lists.adiscon.com
> > [mailto:phplogcon-dev-bounces at lists.adiscon.com] On Behalf Of
> > Brian Shea
> > Sent: Wednesday, December 07, 2005 5:01 PM
> > To: phplogcon-dev at lists.adiscon.com
> > Subject: Re: [Phplogcon-dev] duplicated code
> >
> > 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
> > >
> > _______________________________________________
> > Phplogcon-dev mailing list
> > http://lists.adiscon.net/mailman/listinfo/phplogcon-dev
> >
> _______________________________________________
> Phplogcon-dev mailing list
> http://lists.adiscon.net/mailman/listinfo/phplogcon-dev
>



More information about the Phplogcon-dev mailing list