Not including file if in certain directory in PHP...

Associate
Joined
29 Dec 2004
Posts
2,252
I have a problem.

I would like to include a file "test.php" in every page except pages that are in a folder "/board/". Can php do this?

So far i have

include 'test.php';

But is there something i can do like...

if curdir = /board/ {
include 'nothing';
}
else {
include 'test.php';
}

Obviously i don't actually know much PHP, so any help would be appreciated... :p
 
You're thinking about it kinda backwards. It's simpler just to think "only include file X if the URL does not contain /board/".

Code:
if(!preg_match('#^/board/.*#i', $_SERVER['REQUEST_URI']))
    require_once 'file.php';
 
Thanks Rob thats perfect.

Quick question....should this:

function getPunboUserID()
{
global $database;

$query1 = "SELECT id FROM site_users "
."WHERE name=$my->name";
$database->setQuery( $query1 );
$Itemid1 = $database->loadResult();
return $Itemid1;
}

Work? As for some reason it just returns a blank result when i echo it...it all seems to be pointing to the right places but is the code right?
 
What's $my? It's not defined anywhere in that code and is thus not in scope.

Are you thinking about "my" in a VB context, ie to refer to the current object? If so, use $this.
 
robmiller said:
What's $my? It's not defined anywhere in that code and is thus not in scope.

Are you thinking about "my" in a VB context, ie to refer to the current object? If so, use $this.

I am using Joomla (the CMS) and $my is defined in its core code. Other than that - all ok?
 
Back
Top Bottom