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

Include Php File In Page

Xarcell

Well-known member
#1
I'm not even sure this can be done.

I purchased a baby name script and is installed at my forum root different in a different DB. Now I'm trying to include it into a page.

This is what I have:

library/XenForo/Pages/BabyNames.php

Code:
<?php
class XenForo_Pages_BabyNames
{
     public static function includeFile(XenForo_ControllerPublic_Abstract  $controller, XenForo_ControllerResponse_Abstract &$response)
    {
        ob_start();
        include('http://inspireromance.com/babynames/index.php');
        $babyNames = ob_get_contents();
        ob_end_clean();

        $params = array(
            'babyNames'  => $babyNames
        );

        $response->params = array_merge(
            $response->params,
            $params
        );
    }
}
Page:
Code:
<div class="baseHtml messageText">

{xen:raw $babyNames}

</div>
PHP Callback: XenForo_Pages_BabyNames :: includeFile


The error I get when visiting the page:

Server Error

include() [function.include]: URL file-access is disabled in the server configuration
  1. [*]XenForo_Application::handlePhpError() in XenForo/Pages/BabyNames.php at line 7
    [*]XenForo_Pages_BabyNames::includeFile() in XenForo/Pages/BabyNames.php at line 7
    [*]XenForo_Pages_BabyNames::includeFile() in XenForo/ControllerPublic/Page.php at line 46
    [*]XenForo_ControllerPublic_Page->actionIndex() in XenForo/FrontController.php at line 310
    [*]XenForo_FrontController->dispatch() in XenForo/FrontController.php at line 132
    [*]XenForo_FrontController->run() in /home/xarcell/public_html/inspireromance.com/index.php at line 15
Anything I can do to make this work?
 

Jake Bunce

XenForo moderator
Staff member
#2
Code:
include('http://inspireromance.com/babynames/index.php');
Try using the server path instead of the URL.
 

Xarcell

Well-known member
#3
Ok, this is the error I get now.

Server Error

Use of undefined constant letter - assumed 'letter'
  1. [*]XenForo_Application::handlePhpError() in /home/xarcell/public_html/inspireromance.com/babynames/index.php at line 4
    [*]include() in XenForo/Pages/BabyNames.php at line 7
    [*]XenForo_Pages_BabyNames::includeFile() in XenForo/ControllerPublic/Page.php at line 46
    [*]XenForo_ControllerPublic_Page->actionIndex() in XenForo/FrontController.php at line 310
    [*]XenForo_FrontController->dispatch() in XenForo/FrontController.php at line 132
    [*]XenForo_FrontController->run() in /home/xarcell/public_html/inspireromance.com/index.php at line 15
It separate databases, could that be the cause?
 

Jake Bunce

XenForo moderator
Staff member
#4
Use of undefined constant letter - assumed 'letter'

[*]XenForo_Application::handlePhpError() in /home/xarcell/public_html/inspireromance.com/babynames/index.php at line 4
What is on line 4 of that file?

It looks to me like that script is not compatible with the level of PHP error reporting used by xenForo. It runs fine on its own. Perhaps you can modify the script to change error reporting levels before and after its execution:

http://php.net/manual/en/function.error-reporting.php

Try adding this to the beginning of the script:

Code:
error_reporting(E_ERROR);
And add this to the end of it to change it back to the level xenForo uses:

Code:
error_reporting(E_ALL | E_STRICT & ~8192);
 

Xarcell

Well-known member
#5
I don't know php.

But I think line 4 is a variable?
Code:
$letter=$_GET[letter];
I added what you said to the beginning and end of the index.php file. Should it be added to all of the files?

Anyhow, this is the error it gives now:
Server Error

Undefined variable: data
  1. [*]XenForo_Application::handlePhpError() in /home/xarcell/public_html/inspireromance.com/babynames/origin.php at line 53
    [*]include() in /home/xarcell/public_html/inspireromance.com/babynames/template.php at line 2
    [*]include() in /home/xarcell/public_html/inspireromance.com/babynames/index.php at line 137
    [*]include() in XenForo/Pages/BabyNames.php at line 7
    [*]XenForo_Pages_BabyNames::includeFile() in XenForo/ControllerPublic/Page.php at line 46
    [*]XenForo_ControllerPublic_Page->actionIndex() in XenForo/FrontController.php at line 310
    [*]XenForo_FrontController->dispatch() in XenForo/FrontController.php at line 132
    [*]XenForo_FrontController->run() in /home/xarcell/public_html/inspireromance.com/index.php at line 15
 

Jake Bunce

XenForo moderator
Staff member
#6
Anyhow, this is the error it gives now:

Undefined variable: data
That is another error which can be suppressed with lower levels of error reporting. Try changing the error reporting level in that file as well (babynames/origin.php).

Ultimately this is a problem with the babynames script. But I think you can suppress it by changing the error reporting level.
 

Xarcell

Well-known member
#7
Ok, I added the error handling to the origin.php and now I get a blank page.

origin.php
Code:
//include "conn.php";

error_reporting(E_ERROR);

//create a cache every 3 hour

function writeCache($data,$cacheFile='default_cache.txt'){
    if(!$fp=fopen($cacheFile,'w')){
         trigger_error('Error opening cache file');
         exit();
    }
    if(!flock($fp,LOCK_EX)){
        trigger_error('Unable to lock file');
        exit();
    }
    if(!fwrite($fp,serialize($data))){
        trigger_error('Error writing to cache file');
        exit();
    }
    flock($fp,LOCK_UN);
    fclose($fp);
}
function readCache($cacheFile){
     if(!file_exists($cacheFile)){
         trigger_error('Invalid cache file');
         exit();
     }
     return unserialize(file_get_contents($cacheFile));
}
   
/************************************************************************************************/

//Main body of the page
//Check if there is an existing cache and if time is not yet expired
// define cache file
$cacheFile="cache/origins.txt";
// define expire time in seconds (24 hours)
$expireTime=486400;
// check to see if cache file is valid (time triggered caching)

if(file_exists($cacheFile) && filemtime($cacheFile) > (time()-$expireTime)){
    $data=readCache($cacheFile);
                              }
else{

$sq = "SELECT origin FROM names group by origin order by origin,name";
$rs = mysql_query($sq) or die(mysql_error());
 
while($datas=mysql_fetch_array($rs)){
           $data .= "<option value='$datas[origin]'>$datas[origin]</option>";
                         }

writeCache($data,$cacheFile);

}

$options = $data;

error_reporting(E_ALL | E_STRICT & ~8192);
 

Jake Bunce

XenForo moderator
Staff member
#8
A blank page is often a suppressed error. Try adding this line to your library/config.php file:

Code:
ini_set('display_errors', true);
That may reveal an error message on the blank page.