1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Including external PHP-files into a page callback method

Discussion in 'XenForo Development Discussions' started by kiwhen, Nov 1, 2012.

  1. kiwhen

    kiwhen Member

    I'm trying to create a page node that I can use to list and edit bug reports for a game server. I have a pretty good idea on how to do this using PHP, but I'm a bit of a rookie when it comes to putting this stuff into a Xenforo page node. I've created a PHP-file that's tied into the PHP callback-function for said page, and that works just fine. I can print whatever I want using this file, but for some reason, I can't use the PHP include and require-methods. I assume this is a problem related to the rewrite engine - I'm using search engine-friendly URLs for my forum, so the direct link to the page node looks something like this:

    From experience, I know that forward slashes in the query string can cause some interesting results when trying to include additional files.

    I have confirmed that the file I'm trying to include is really present at the URL's I've given for the include-method, and I've tried pretty much all manner of combinations to get this to work. I've tried giving both an absolute URL (all the way from http://) and a relative path, using just "filename.php", "../../filename.php", "library/myfolder/myfile.php" and so on.

    Here's a stripped-down version of my stylish callback-file:
    class FOLDER_FILE {
    public static function METHOD(XenForo_ControllerPublic_Abstract $controller, XenForo_ControllerResponse_Abstract &$response) {
    $output = "A";
    include('URL') or die();
    $response->params['output'] = $output;
    This results in a simple 404 error:
    "include(1) [function.include]: failed to open stream: No such file or directory"

    Upon removing the include-line, the page will correctly display the usual Xenforo layout with a capital "A" on it. The included file is supposed to change $output to become a capital "B" instead.

    How can I include external PHP-files into a page callback method?

    PS: The file I'm including is in the same folder as the callback-method.
  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

  3. kiwhen

    kiwhen Member

    That wouldn't do much good, as far as I can tell. Neither file creates any kind of output. The problem is that the URL passed to the include-method appears to be invalid, even if I pass the exact absolute URL to the file.

    I suppose I could write the whole script in the callback-file itself, but this would cause a lot of mess. :(

    PS: Tested the output buffer just for kicks; the results didn't change.
  4. Luke F

    Luke F Well-Known Member

    BoostN likes this.

Share This Page