Page 1 of 1

Include_Once ???

Posted: Thu Feb 19, 2004 5:25 pm
by kukur
From what I have found doing a search I don't think this may be able to work on Win2000 but I will see if those brighter than I can confirm or deny it.

In my site I have an

include_once("php/headerad.php");

my Php scripts are in a folder php and documents in the root folder of the site work fine.

But I would like to put documents in subfolders of the site (we are a small newspaper and I would like to keep the sections seperate) like /sports/article1.php

When I try to change the script to:

include_once("www.mydomain.com/php/headerad.php");
include_once("http://mydomain.com/php/headerad.php");

I get the fun error:

Warning: main(http://www.mydomain.com/php/headerad.php): failed to open stream: No such file or directory

Is there a way to tell the script to find the .php outside of the current local directory?

TIA

Posted: Thu Feb 19, 2004 5:30 pm
by uberpolak
You can use periods to move up the directory structure.

For example, if you're currently on a page /sports/article1.php

Code: Select all

<?php
include_once('../php/headerad.php');
?>
I think that's what you're asking about.

Posted: Thu Feb 19, 2004 5:35 pm
by kukur
uber,

Good thought. I tried that and still get the error:

Warning: main(../php/headerad.php): failed to open stream: No such file or directory

In my root folder I have:

index.php

and folders

php/headerad.php
sports/index.php


With the include_once script of:

include_once("php/headerad.php");

the index page in the root folder is fine but anything in a lower folder directory can't find it.

Posted: Thu Feb 19, 2004 5:40 pm
by uberpolak
If that doesn't do it I don't know what to tell you, in a similar situation that works for me.

Posted: Thu Feb 19, 2004 5:51 pm
by kukur
Well, I found this digging around...

include_once($DOCUMENT_ROOT . "../php/headerad.php");

Now the funny thing is the pages in sports/ folder pull the script fine.

But the index page in the root folder doesn't 8O

If I can't find any work around, I will use this script and use a redirect html page to send my 'index' into a sub folder like the rest I guess.


Thanks for the effort uber. :)

Posted: Thu Feb 19, 2004 5:54 pm
by uberpolak
Hmm, if it works with your docroot included, have you tried using root relative links (pay close attention)?

Code: Select all

<?php
include_once('/php/headerad.php');
?>
That beginning slash means it will look for a folder called 'php' in the root directory, no matter where you call it from. Try that.

Posted: Thu Feb 19, 2004 6:00 pm
by kukur
Tried that...

neither the doc in the root folder, nor the one in ths sub likes that one! :D


I have a feeling this is what I am running into...
Windows versions of PHP prior to PHP 4.3.0 do not support accessing remote files via this function, even if allow_url_fopen is enabled.

I think I only have 4.1 on the server. Dagnabit.