Help - Search - Members - Calendar
Full Version: Archives and Using PHP includes
Movable Type Community Forum > Additional Resources > Tips and Tricks
thoughtmarket
I have set up my index to include some newsfeeds. All of the index templates work perfectly in displaying the subject matter specific feeds, using:
CODE
<? include ('news/feeds.php'); ?>
.

The feeds sit in the /news directory.

But when I take a look at an archive page (of which there is only one, just for testing), I see the following error messages:
CODE
Warning: main(news/feeds.php): failed to open stream: No such file or directory in /var/www/html/blogarch/2005/02/index.php on line 293
and
CODE
Warning: main(): Failed opening 'news/feeds.php' for inclusion (include_path='.:/php/includes:/usr/share/php') in /var/www/html/blogarch/2005/02/index.php on line 293


I suspect a pathing issue, but just cannot figure out what to do to fix.

Also, the entire site, including the archive files, are PHP.

Any assistance is appreciated.
imabug
include()
QUOTE
Files for including are first looked in include_path relative to the current working directory and then in include_path relative to the directory of current script. E.g. if your include_path is ., current working directory is /www/, you included include/a.php and there is include "b.php"  in that file, b.php is first looked in /www/  and then in /www/include/


try using an absolute path to feeds.php
thoughtmarket
I am not sure if I am interpreting "absolute" correctly, but when I tried:
CODE
<? include ('http://www.sitename.com/news/feeds.php'); ?>
I get:
CODE
Warning: main(http://www.sitename.com/news/feeds.php): failed to open stream: HTTP request failed! HTTP/1.1 401 Authorization Required in /var/www/html/index.php on line XXX

Warning: main(): Failed opening 'http://www.sitename.com/news/feeds.php' for inclusion (include_path='.:/php/includes:/usr/share/php') in /var/www/html/index.php on line XXX
for all the pages in the base directory, and those in the lower directories.

I also tried using ../ in front of "news/feeds.php, and got these errors for all pages:
CODE
Warning: main(): Unable to access ../news/feeds.php in /var/www/html/index.php on line XXX

Warning: main(../news/feeds.php): failed to open stream: No such file or directory in /var/www/html/index.php on line XXX

Warning: main(): Failed opening '../news/feeds.php' for inclusion (include_path='.:/php/includes:/usr/share/php') in /var/www/html/index.php on line XXX


When I tried ./ in front, the error is the same as the first.

Thanks for the help.
thoughtmarket
Arghh.

User error. When I looked back at the second group of error messages, I realized it was a .htaccess issue. The site is password protected until the build is finished, hence the Authorization required error.

Thanks for the input on the absolute reference. That fixed it. It works when I ## out the lines in .htaccess for the /html directory.

Cheers!
imabug
QUOTE
I am not sure if I am interpreting "absolute" correctly, but when I tried:
CODE
<? include ('http://www.sitename.com/news/feeds.php'); ?>

that would be a URL. An absolute path refers to the file system path, i.e /path/to/news/feeds.php. appending a ../ (which means 'in the parent directory' in front as you did will work for the archives directory. it will break again for subdirectories in your archives directory, or if you're using the same code in your index template. using ./ means 'in the current directory'.
thoughtmarket
Thanks for the info. It is now working when I pound out the access entries in .htaccess.

I appreciate the direction.

Have a great remaining weekend.

smile.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.