Welcome, Guest. Please login or register.
Did you miss your activation email?
February 12, 2012, 04:56:13 PM

Login with username, password and session length
Search:     Advanced search
Interested in joining the WebsiteBaker team?
For more Information read here or on our new website.
149665 Posts in 21100 Topics by 7538 Members
Latest Member: ionline
* Home Help Search Login Register
Pages: [1]   Go Down
Print
Author Topic: Problem with Inline Wrapper - Please help!  (Read 3242 times)
4bizmedia

Offline Offline

Posts: 41



WWW
« on: March 23, 2007, 01:33:10 AM »

Hi,

I have installed wb onto a new server that is running php 4.44 and apache 3.

The wb stuff all works fine, but when I installed the inline wrapper module, I got this error

Fatal error: Call to undefined function: apache_request_head ers() in /home2/prestige/public_html/main/modules/inlinewrapper/WebPage.php on line 170

Can someone please help?

regards
Paul
Logged
kweitzel
Forum administrator
*****
Offline Offline

Posts: 6820


WWW
« Reply #1 on: March 23, 2007, 07:01:35 AM »

And now, please try again: Apache V3 does not exist as official download. Which Version are you using?

cheers

Klaus
Logged

WebsiteBaker Org e.V. - for WebsiteBaker

mickpage
Guest
« Reply #2 on: March 26, 2007, 11:20:47 AM »

The apache_request_head ers() function is only supported when PHP is installed as an Apache module. I guess you have PHP running as CGI (which is how my host has recently moved). So, looks like the module needs fixing to accomodate this.
Logged
Panther

Offline Offline

Posts: 168



WWW
« Reply #3 on: May 24, 2007, 03:37:52 PM »

I'm running in to this same problem. Feh.
Logged
Turskis

Offline Offline

Posts: 50


« Reply #4 on: July 04, 2007, 07:33:21 PM »

Me too. Does anyone have a working solution on this?
Logged
pcwacht
Guest
« Reply #5 on: July 04, 2007, 09:04:01 PM »

Not a working solution but more info on apache_get_headers();
http://nl3.php.net/manual/en/function.apache-request-headers.php

Here is allso a bypass for this function:
Code:
<?php
function request_headers()
{
    if(
function_exists("apache_request_headers")) // If apache_request_headers() exists...
    
{
        if(
$headers apache_request_headers()) // And works...
        
{
            return 
$headers// Use it
        
}
    }

    
$headers = array();

    foreach(
array_keys($_SERVER) as $skey)
    {
        if(
substr($skey05) == "HTTP_")
        {
            
$headername str_replace(" ""-"ucwords(strtolower(str_replace("_"" "substr($skey05)))));
            
$headers[$headername] = $_SERVER[$skey];
        }
    }

    return 
$headers;
}
?>


Have fun,
John
Logged
Turskis

Offline Offline

Posts: 50


« Reply #6 on: July 05, 2007, 04:45:07 PM »

Thanks for reply. I think i fixed it. Not sure though, because I know next to nothing about coding. I replaced following code in Inline Wrapper's file named "WebPage.php" with the code that pcwacht advised:

Code:
$lHeaders = apache_request_headers();
    if ((isset($lHeaders['Cache-Control']) && $lHeaders['Cache-Control'] == 'no-cache')
        || (isset($lHeaders['Pragma']) && $lHeaders['Pragma'] == 'no-cache')) {
      $lForceReload = true;
    }

        // Try to load the cached ETag.
        if (!$lForceReload) {
          $this->loadCachedMetaInfo();
        }

        // Set cookie/session?
        $lCookie = false;
        if (isset($_SESSION['wrappercookie'])) {
            $lCookie = $_SESSION['wrappercookie'];
        }

        // Capture return headers.
        $lReturnHeaders = array();
Logged
pcwacht
Guest
« Reply #7 on: July 05, 2007, 05:02:48 PM »

Simplest test to see if that fixes it is to see if it works with the changed code Wink

Does it work?
btw did you change the call to the function apache_request_head ers into request_headers ??

What this code does:
Normally the inline module uses a build in php function - apache_request_head ers();
This function doesn't work on every install, has to do with the way php is implemented (cgi or not) and the version of php

The line:
if(function_exists("apache_request_head ers")) // If apache_request_head ers() exists...

tests to see if your php knows the apache_request_head ers function, if it does it will be used and if it doesn't the rest of the code will be used to emulate that function.


In order for it to work you need to add the snippet I posted in the same file wich uses apache_header_reque sts and rename the exisiting call to header_requests so it will execute the new code

Have fun,
John
Logged
Turskis

Offline Offline

Posts: 50


« Reply #8 on: July 06, 2007, 01:03:30 PM »

I meant it seems to be working, because the pages are shown correctly. But I'm not sure, if this has some side effects.

Yes, I changed the call to the function. Copy-pasted the code as it is.
Logged
pcwacht
Guest
« Reply #9 on: July 06, 2007, 09:26:53 PM »

K, then it seems to work ok.

Good job Tongue

John
Logged
glogo

Offline Offline

Posts: 22


« Reply #10 on: July 10, 2007, 09:30:09 AM »

Dear pcwacht,

I am having this problem also. I tried your snippet and it does not seem to work. Maybe you can explain just a little more about the phrase:

Quote
add the snippet I posted in the same file which uses apache_header_reque sts and  rename the exisiting call to header_requests so it will execute the new code

To which "same file" are you referring and exactly where do you change "call". I did as best as I could but I am getting an error:

Code:
Fatal error: Cannot redeclare request_headers() (previously declared in /home/wb/modules/inlinewrapper/WebPage.php:173) in /home/wb/modules/inlinewrapper/WebPage.php on line 171

Perhaps I am just missing a closing bracket somewhere. I don't know.

Here is my file:

Code:
<?php

/*

 Copyright (C) 2005 - 2006, Domeo / Avisi B.V.

 WebsiteBaker inline wrapper module is free software; you can
 redistribute it and/or modify it under the terms of the GNU
 General Public License as published by the Free Software
 Foundation; either version 2 of the License, or (at your
 option) any later version.

 WebsiteBaker is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with websitebaker; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

*/

// Direct request, process document.
if (!defined("WB_URL") && isset($_GET['wrapperurl'])) {

    require_once(
"functions.php");
    require_once(
"WebPage.php");
    require_once(
"HtmlPage.php");
    require_once(
"CssFile.php");

    
$lUrl urldecode($_GET['wrapperurl']);

    
// Test filetype and forward to correspondending action class.
    
$lPage false;
    if (
str_endswith(".css"strtolower($lUrl))) {
        
// process CSS
        
$lPage = new CssFile($lUrl);
    } else {
        
// process HTML
        
$lPage = new HtmlPage($lUrl);
    }

    
$lPage->display();
}


/**
 * @package pages
 *
 * Contents web page.
 */
class WebPage {

    
// Full URL of web page, including protocol, domain and request parameters.
    
var $url;
    
// ETag page
    
var $eTag;
    
// Page contents.
    
var $contents;
    
// Cache and cache meta info location.
    
var $cachedir;
    
// Contents rewritten?
    
var $processed;
    
// Is this a cached version or a fresh server document?
    
var $cached;
    
// Content-type
    
var $contenttype;
    
// Do not cache this page (HTTP POST reply will never be cached)
    
var $docache;
    
// Forward HTTP GET variables?
    
var $forwardget;

    
/**
     * Constructor.
     *
     * @param $pUrl string  The absolute URL.
     */
    
function WebPage($pUrl) {

        
$this->url $pUrl;

        
// Use websitebakers temp dir for caching
        
$this->cachedir IWCACHEDIR;

        
// Default settings
        
$this->eTag "";
        
$this->processed false;
        
$this->cached false;
        
$this->docache true;
        
$this->forwardget false;

        
// Add trailing slash, convert http://www.google.com to http://www.google.com/
        
if (!str_contains("/"substr($pUrl8))) {
            
$this->url .= "/";
        }
        if (
str_contains(" "$this->url)) {
            
$this->url str_replace(" ""%20"$this->url);
        }
    }


    
/**
     * Get rewritten contents.
     *
     * @return The rewritten contents.
     */
    
function getContents() {

        
// Process this document only ones.
        
if (!$this->processed) {

            
// Try to load external document.
            
$this->loadRemoteDocument();

            
// Can we use a cached version?
            
if ($this->processed) {
                return;
            }

            
// No, do the full document rewrite.
            
$this->processDocument();
        }
    }


    
/**
     * Display the document
     */
    
function display() {

        
$this->getContents();

        
// Add some debugging
        
$lDebugText "";
        if (
strtolower($this->contenttype) == "text/css") {
            
$lDebugText $this->cached "/* Inline wrapper: Cached version */" "/* Inline wrapper: Fresh content */";
        } else {
            
$lDebugText $this->cached "<!-- Inline wrapper: Cached version -->" "<!-- Inline wrapper: Fresh content -->";
        }

        print 
"\n<div id=\"wrapper\">\n";
        print 
$lDebugText "\n" $this->contents;
        print 
"</div>\n";

        
// Flush Apache cache
        
flush();

        
// At last, save rewritten contents to cache.
        // HTTP POST reply will never be cached.
        
$this->saveToCache();

        
// Clean the cache once in a while
        
$this->cleanCache();
    }


    
// ======================================================
    //  Private methods
    // ======================================================


    /**
     * Get contents external document or use cached version.
     */
    
function loadRemoteDocument() {

    
// Detect force reload.
    
$lForceReload false;

function 
request_headers()
{
    if(
function_exists("apache_request_headers")) // If apache_request_headers() exists...
    
{
        if(
$headers apache_request_headers()) // And works...
        
{
            return 
$headers// Use it
        
}
    }

    
$headers = array();

    foreach(
array_keys($_SERVER) as $skey)
    {
        if(
substr($skey05) == "HTTP_")
        {
            
$headername str_replace(" ""-"ucwords(strtolower(str_replace("_"" "substr($skey05)))));
            
$headers[$headername] = $_SERVER[$skey];
        }
    }

    return 
$headers;
}



    
// If there are HTTP POST variables available, grab those variables and do a POST instead of a GET request.
        
if (sizeof(array_keys($_POST))) {

            
// Do a HTTP POST
            // Als php_value setting 'always_populate_raw_post_data' aan staat (.htaccess of php.ini), hebben we
            // beschikking over de originele POST data. Deze 1-op-1 forwarden
            
if (isset($HTTP_RAW_POST_DATA)) {
                
$raw_post $HTTP_RAW_POST_DATA;
            } else {
                
$raw_post implode("\r\n"file('php://input'));
            }
            if (
$raw_post) {
                
$this->contents doPost($this->url$lCookie$raw_post$lReturnHeaderstrue);
            } else {
                
$this->contents doPost($this->url$lCookie$_POST$lReturnHeaderstrue);
            }

        } else {

            
// Attach all HTTP GET variables to URL
            
if ($this->forwardget) {
                foreach (
$_GET as $lKey => $lValue) {
                    
$this->url .= str_contains("?"$this->url) ? "&" "?";
                    
$this->url .= "$lKey=" urlencode($lValue);
                }
            }

            
// Do a HTTP GET request.
            
$lRequestHeaders = array();
            if (!empty(
$this->eTag) && !$lForceReload) {
                
// Check if page is modified.
                
$lRequestHeaders[] = "If-None-Match: " $this->eTag;
            }

            
// Content types we will accecpt
            
$lAcceptedContentTypes = array("text/html""text/plain");
            
$this->contents doGet($this->url$lRequestHeaders$lCookie$lReturnHeaderstrue$lAcceptedContentTypes);

            
// Unknown content-type, show the link
            
if ($this->contents == false) {
                echo 
"<a href=\"" $this->url "\">" $this->url "</a>\n";
                exit(
0);
            }
        }


        
// Do not cache by default.
        
$this->docache false;

        
// Save cookies/session external page?
        
if (isset($lReturnHeaders['set-cookie'])) {
            
$_SESSION['wrappercookie'] = $lReturnHeaders['set-cookie'];
        }

        
// If status Ok, remember the ETag.
        
if (str_contains("200"$lReturnHeaders['status'])) {

            if (isset(
$lReturnHeaders['etag'])) {
                
$this->eTag $lReturnHeaders['etag'];
            }
            
$this->contenttype $lReturnHeaders['content-type'];
            
// Only cache GET requests.
            
if (!sizeof(array_keys($_POST))) {
                
$this->docache true;
            }
        }

        
// If status "302 Moved Temporarily" or "302 Object moved", forward to new page.
        
elseif (str_contains("302"$lReturnHeaders['status'])) {

            
$lForwardUrl $lReturnHeaders['location'];

            
// Make relative URL absolute
            
if (!str_startswith("http"$lForwardUrl)) {
                if (
str_startswith("/"$lForwardUrl)) {
                    
$lForwardUrl $this->getRootPath() . substr($lForwardUrl1);
                } else {
                    
$lForwardUrl $this->getPath() . $lForwardUrl;
                }
            }

            
$this->url $lForwardUrl;
            
$this->eTag "";
            
$this->loadRemoteDocument();

            
// Remove HTTP POST variables
            
if (sizeof(array_keys($_POST))) {
                foreach (
$_POST as $lKey => $lValue) {
                    unset(
$_POST[$lKey]);
                }
            }

        }

        
// Document not changed. Keep using the cached version of the contents.
        
elseif (str_contains("304"$lReturnHeaders['status'])) {

            if (
$this->loadFromCache()) {
                
// We are done. No further processing.
                
$this->processed true;
                
$this->cached true;
            }
        }
    }


    
/**
     * Rewrite document for inline usage.
     */
    
function processDocument() {
        
$this->contents "<p>Error: Process document in inheritance class!</p>\n\n";
        
$this->processed true;
    }


    
/**
     * Try to load the contents from cache.
     *
     * @return boolean  True if success.
     */
    
function loadFromCache() {

        
$lTmpInfoFile $this->cachedir safe_filename($this->url);
        
$this->contents trim(implode("", @file($lTmpInfoFile)));
        return 
true;
    }


    
/**
     * Save contents and meta data(ETag/Content-Type) to cache.
     *
     * @return boolean  True if success.
     */
    
function saveToCache() {

        
// Cache not functional when no Etag available
        
if (!$this->docache || $this->eTag == "") {
            return 
false;
        }

        
// Save meta data and contents
        
if ($this->saveMetaInfoToCache()
                    && 
$this->saveContentsToCache()) {
            return 
true;
        }
        return 
false;
    }

    
/**
     * Save contents to cache.
     *
     * @return boolean  True if success.
     */
    
function saveContentsToCache() {

        
$lTmpFile $this->cachedir safe_filename($this->url);
        
$fp = @fopen($lTmpFile"w+");

        
// invalid filepointer, probably no rights to write.
        
if (!$fp) {
            
// Tempdir not available?
            // Create directory and try again.
            
@mkdir($this->cachedir);
            @
chmod($this->cachedir0777);
            
$fp = @fopen($lTmpFile"w+");

            if (!
$fp) {
                return 
false;
            }
        }

        
// do an exclusive lock
        
if (flock($fpLOCK_EX)) {

            
fwrite($fp$this->contents);

            
// release the lock
            
flock($fpLOCK_UN);

        } else {
            
//echo "Couldn't lock the file !";
            
return false;
        }

        
// Close filepointer
        
fclose($fp);
        return 
true;
    }


    
/**
     * Try to load Etag and Content-Type of cached version.
     *
     * @return boolean  True if success.
     */
    
function loadCachedMetaInfo() {

        
$this->eTag "";

        
// If GET parameter 'forcereload' is set, ignore the cached version.
        
if (isset($_GET['forcereload'])) {
            return 
false;
        }

        
$lTmpInfoFile $this->cachedir safe_filename($this->url) . ".info";
        
$lLines = @file($lTmpInfoFile);

        if (
$lLines == false || !is_array($lLines)) {
            return 
false;
        }

        
// Search for E-tag and Content-Type.
        
for ($i=0$i sizeof($lLines); $i++) {
            if (
str_startswith("Etag: "$lLines[$i])) {
                
$this->eTag substr($lLines[$i], strlen("Etag: "));
            }
            if (
str_startswith("Content-Type: "$lLines[$i])) {
                
$this->contenttype substr($lLines[$i], strlen("Content-Type: "));
            }
        }

        return 
true;
    }


    
/**
     * Save E-tag and Content-Type to cache.
     *
     * @return boolean  True if success.
     */
    
function saveMetaInfoToCache() {

        
$lTmpInfoFile $this->cachedir safe_filename($this->url) . ".info";
        
$fp = @fopen($lTmpInfoFile"w+");

        
// Invalid filepointer, probably no rights to write.
        
if (!$fp) {
            return 
false;
        }

        
// Do an exclusive lock
        
if (flock($fpLOCK_EX)) {

            
fwrite($fp"Etag: "$this->eTag "\n");
            
fwrite($fp"Content-Type: " $this->contenttype "\n");

            
// Release the lock
            
flock($fpLOCK_UN);

        } else {
            
//echo "Couldn't lock the file !";
            
return false;
        }

        
// Close filepointer
        
fclose($fp);
        return 
true;
    }


    
/**
     * Absolute path of URL with trailing slash.
     * http://www.google.com/images/bla.png -> http://www.google.com/images/
     * http://www.google.com/images/ -> http://www.google.com/images/
     * http://www.google.com/images -> http://www.google.com/
     *
     * @return string  The path
     */
    
function getPath() {
        if (
substr($this->url, -11) == "/") {
            return 
$this->url;
        }
        
// Chop filename and add trailing slash.
        
return dirname($this->url) . "/";
    }


    
/**
     * Absolute root path of URL with trailing slash.
     * http://www.google.com/images/bla.png -> http://www.google.com/
     *
     * @return string  The hostname part;
     */
    
function getRootPath() {
        return 
substr($this->url0strpos(substr($this->url8), "/") + 9);
    }


    
/**
     * Get location and name of this included script for direct access.
     *
     * @return string  Full URL to this script.
     */
    
function getThisScriptName() {

        
/*
        $lThisFileName = __FILE__;

        $lScriptFileName = $_SERVER['SCRIPT_FILENAME'];
        $lScriptName = $_SERVER['SCRIPT_NAME'];
        $lRealServerLocation = substr($lScriptFileName, 0, strlen($lScriptFileName) - strlen($lScriptName));
        return substr($lThisFileName, strlen($lRealServerLocation));
        */
        
return WB_URL "/modules/inlinewrapper/WebPage.php";
    }


    
/**
     * Set if all HTTP GET varibales have to be forwarded.
     *
     * @param boolean $pValue  True if forward all HTTP GET variables.
     */
    
function setForwardget($pValue) {
        
$this->forwardget $pValue;
    }


    
/**
     *     Delete cache content older than a month
     */
    
function cleanCache() {

        
// Check cache dir for old content every 1000 hits or so
        
if (rand(0,1000) == 500) {

            
// First flush all cache.
            
flush();

            
// Never timeout
            
set_time_limit(0);
            
rm_cache_files($this->cachedir60 60 24 30);
        }
    }
}

?>


Thanks in Advance
glogo
Logged
lionking

Offline Offline

Posts: 5


« Reply #11 on: September 12, 2007, 10:53:03 AM »

I have this problems too.
But i dont know anything about PHP.

Can u please post the complete fixed file?
Logged
jbs

Offline Offline

Posts: 24


WWW
« Reply #12 on: June 15, 2008, 04:09:08 PM »

I guess this topic got dropped in the middle  huh

I'm having the same problem, except for me, the coding works if there's one inline wrapper section on a page. Put in two and then there's the issue of "Cannot redeclare request_headers". I'm looking for a resolution ...
« Last Edit: June 15, 2008, 04:21:47 PM by jbs » Logged
ruebenwurzel
WebsiteBaker Org e.V.

Online Online

Posts: 7663



WWW
« Reply #13 on: June 16, 2008, 06:38:15 AM »

Hello,

Quote
Put in two and then there's the issue of "Cannot redeclare request_headers".

The answer is in the error message. If once declared (in a first section) you cannot declare this in a second section.

Try it with "require_once".

Matthias
Logged
jbs

Offline Offline

Posts: 24


WWW
« Reply #14 on: June 16, 2008, 03:12:56 PM »

I figured it was something like that -- I've run into the need to do that before. I just can't seem to find where in the code that I added (as given earlier in the discussion).  There's no "require" to change to "require_once."

However, I did find a resolution that seems to work. Enclose the above code with:

if (!function_exists('request_headers')) {

......

}
« Last Edit: June 16, 2008, 04:12:57 PM by jbs » Logged
Pages: [1]   Go Up
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!