dynamicreport.com News Member Login Knowledge Base Site Map
Support Support Ticket Contact Us
Products Drag & Drop Objects Drag & Drop Calendar UNIGEN Web Reporting Code View
Testimonials Downloads
Order

Knowledge Base Print printer-friendly page.

Login

UNIGEN

ddobj

News



Article #1006: Emulating Remote Script Inclusion

 

When dealing with PHP versions prior to the support of remote file inclusion there are alternative ways to devise such functions, but with more effort. Specifically, Windows versions of PHP prior to PHP 4.3.0 do not support accessing remote files via this function, [include()] even if allow_url_fopen is enabled.

The solution below is a less-complex alternative to calling remote scripts almost seamlessly, except that since modifying headers is key, the callback script will be loaded into the browser. The callback script may be the same calling script or a different script and may be either on the "local" calling machine or on a different server. Often times your development efforts are restricted by the version of PHP currently installed on the server(s), and you may not have authorization to update such software. The functional quick fix below is great in such cases.

* Note: When specifying a header it may be wise to suppress or handle every possible error message scenario when calling certain functions. Precede a function with '@' such as with @mail(). Otherwise an error somewhere along the lines of a duplicate header already sent will be issued to the std. output - prematurely terminating the execution of your script.

<?

// this is the script calling a remote script from within itself, place
// it anywhere within the script that the inclusion would be placed

// obtain the file path excluding the current script file
$scriptNext = substr (__FILE__, 0, strrpos (__FILE__, "\\") + 1);
// append the script to be called after the remote script has finished
$scriptNext .= "after_interface.php";
$scriptNext .= "?param1=optionalparams"; // optional

// versions of PHP not supporting remote script inclusion -- lets emulate it
// break-down of remote script location and optional params
$remote_loc = "http://172.12.47.32:33000/mail/interface.php";
$remote_params = "?param1=apples&param2=oranges"; // optional
$remote_callnext = "&url=".urlencode ($scriptNext);

// this is the equivalent of a remote script include not available in earlier PHP versions
header ("Location: ".$remote_loc.$remote_params.$remote_callnext);

?>

Code View - dynamicreport.com


<?

// this is the remote script called by the calling script from a
// different server.

ob_start (); // necessary to buffer output before browser output

// ... place any code here
// in addition to output for other purposes, you may
// wish to provide status reports on the processing
// by passing variable parameters to the next script
// e.g.
$params_next = "&report=$info"; // optional

ob_end_clean (); // necessary to clear output buffer

// this will execute the intended script after this remote script
header ("Location: ".$_GET['url'].$params_next);

// Specified URL was passed from calling script, parameters optional

?>

Code View - dynamicreport.com

 

 


Back to article listing

 



 

Copyright © 2007-2008 Interaxis. All rights reserved.
Contact Webmaster