WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Includes not Including, Warnings halting script (9 posts)

  1. MikeCherim
    Member
    Posted 7 years ago #

    Is anyone aware of Apache server or PHP settings that would stop this from working:

    <?php include("".$install_path."/".$theme_path."/aFileName.php"); ?>

    Install path in this case is: http://www.domain.com/blog/; and theme path is wp-content/themes/themeName

    This has been extensively tested and works everywhere so far except on one server that I'm aware of. Also, the files that are being included are indeed available. What's even stranger is the error log is reporting PHP Warnings that these includes aren't including and it's halting the script (for a warning). And guess what, the error is showing the correct path to these files and they are existing.

    Any ideas? Thanks.
    Mike

    PS: Here's the log output (with some substitutions):

    [client 00.00.00.00] PHP Warning: main(http://www.domain.com/blog/wp-content/themes/themeName/aFileName.php):
    failed to open stream: HTTP request failed! \x80' \xff\xbf\x7f in www/XXXXX/public_html/wordpress/wp-content/themes/themeName/header.php on line 26

  2. Arnee
    Member
    Posted 7 years ago #

    Hi,

    do you really want to include this file over HTTP? If you want to include this file on your blog and the target file is on the same server/blog, you might use the local path to include it like /usr/local/www/bla.php instead of HTTP.

  3. MikeCherim
    Member
    Posted 7 years ago #

    I did it that way because it's a public theme and I was trying to make sure it works regardless of install path. Preferrably I'd use a relative path and not add all that extra PHP, but I was unable to do that for a few reasons (I'd explain but I'd be getting too far off-topic).

    It seems to work just fine elsewhere though. It's just one installation throwing a fit.

    Thanks
    Mike

  4. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    This will fail if the server's php installation has the allow_url_fopen flag set to false, or if it's a version of PHP prior to 4.3.0 on Windows machines.

    See here for more info: http://www.php.net/manual/en/ref.filesystem.php#ini.allow-url-fopen

    The short of it is that given the wide variety of configs and versions out there, using a URL with include* and require* is unreliable. Best thing: Don't do that. Put the file local instead and give an absolute path to it. In WordPress you can do this with the ABSPATH stuff. Like ABSPATH.'wp-content/plugins' is the plugins directory.

    Since you say you're making a theme, just use TEMPLATEPATH. That is the current theme's directory. So TEMPLATEPATH.'/functions.php' would be your theme's functions.php file, for example. See here for more info: http://codex.wordpress.org/Theme_Development

  5. MikeCherim
    Member
    Posted 7 years ago #

    Thanks Otto42. Unfortunately I think I'm still missing the mark.

    PHP Version is 4.3.9
    allow_url_fopen is set to "on" (That's what it says when looking at phpinfo() which I am assuming is 'true' )

    Still puzzled :(

    Mike

  6. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    Well, I don't exactly know what the problem is then, but still, why bother with all that stuff when you have TEMPLATEPATH?

  7. MikeCherim
    Member
    Posted 7 years ago #

    Like I said, long story, but in a nutshell there are theme files that are not part of WordPress, yet these files still call for and use (share) certain WP files like the footer.php. In other words on some pages, there is no get_header and no WP fucntions. Now, on the flip side, some of the regular WP theme files are using some of my includes for the various configurations I make availble.

    To best understand I guess you'd have to download the theme and tear it apart (it was over a 200 hour build). This would be best before saying that it isn't supposed to be done this way (I suspect this may be on your mind, dear reader), as I did have very good reason to make the thing work as I wanted it to. And it is everywhere except one installation. Grrr.

    The theme: http://green-beast.com/seabeast/

    Thanks.
    Mike

  8. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    Ahh. Okay, so you don't have the complete WordPress functionality on some pages. A little weird, but I can understand it. There's a few ways to work around this:

    1. The PHP function "dirname(__FILE__)" will give you the absolute path to the current directory (the one that your PHP file is actually in). If you know the file is in your same directory, no problem.

    2. Use relative paths. This generally works okay. include('../stuff in the parent directory');

    3. If you know the root directory of the blog, include('wp-blog-header.php'); This will give you all the wordpress functionality without outputting any of the actual blog.

    I see what you're talking about in contact.php, but given that that is in the same directory as the php file that you're including, simply using an include('USER_WHATEVER.php'); should work for you there.

    It just seems silly to make an extra hit to the webserver when the file you want is local.

  9. MikeCherim
    Member
    Posted 7 years ago #

    Thanks Otto,

    I totally agree, but I got worried about relative paths in case someone had their blog two directories down or more. Funny, I just wanted this to work for everyone (haha). This one case, if a settings can't be changed on the server, I'll go in a hand code those links for the user since he's been through heck with my theme I feel bad. It'll take a few minutes I guess.

    I do have an idea, though, for a next release to maybe solve this for future installs: I can apply some conditions to link to the file in different ways. I probably explained this poorly, but something like this:

    <?php
    $file = 'filename.php';
    $dir = 'expected/path';
    if ( is_file($dir.$file) ) {
    include($dir.$file);
    } else {
    include('../'.$dir.$file);
    }
    ?>

    Thnaks for your help. I appreciate it.

    Mike

Topic Closed

This topic has been closed to new replies.

About this Topic