[pmwiki-users] Cookbook path

Petko Yotov 5ko at free.fr
Sun Feb 10 18:10:56 CST 2008

DaveG wrote:
> I'm writing a Cookbook (or Recipe, I never know which is which), and I 
> need to get the URL of the location that the script is executing from -- 
> basically the cookbook directory. This way gets me the script *path* 
> (not the URL), which isn't quite what I need:
>     dirname(__FILE__)
> The best I have so far is this (extracted from pmwiki.php), but that 
> assumes the location of cookbook directory.
>     preg_replace('#/[^/]*$#', '/cookbook', $ScriptUrl, 1)

In most installations, the /cookbook/ directory is read-protected: 
cannot and should not be accessed from the internet. It is a security 
risk to have this directory world-readable. I believe even PmWiki places 
there a .htaccess file denying the access.

Should you access your script from the url, try to use a $HandleActions 

$HandleActions['foo'] = 'MyFooFunction';
function MyFooFunction($pagename, $auth="admin")
   $page = RetrieveAuthPage($pagename,$auth,1, READPAGE_CURRENT);
   # here your code
   echo $result;

Now, if you call your page with: http://site/pmwiki.php?action=foo
then the function MyFooFunction() will be executed.

You can see how some other existing recipes do this.


More information about the pmwiki-users mailing list