...

View Full Version : How do you wrap up a piece of code to insert?



instaunt
02-20-2012, 11:43 AM
I have a php CMS code that calls a template based on the URL calling the code. I now have to insert a piece of code that would usually be placed directly in to the PHP page:



$OpenInNewWindow = "1";
$BLKey = "MFECU-J1BMR-TH1J7";
$QueryString = "LinkUrl=".urlencode((($_SERVER['HTTPS']=='on')?'https://':'http://').$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
$QueryString .= "&Key=" .urlencode($BLKey);
$QueryString .= "&OpenInNewWindow=" .urlencode($OpenInNewWindow);

if(intval(get_cfg_var('allow_url_fopen')) && function_exists('readfile')) {
@readfile("http://brokerage.linkadage.com/engine.php?".$QueryString);
}
elseif(intval(get_cfg_var('allow_url_fopen')) && function_exists('file')) {
if($content = @file("http://brokerage.linkadage.com/engine.php?".$QueryString))
print @join('', $content);
}
elseif(function_exists('curl_init')) {
$ch = curl_init ("http://brokerage.linkadage.com/engine.php?".$QueryString);
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_exec ($ch);

if(curl_error($ch))
print "Error processing request";

curl_close ($ch);
}
else {
print "It appears that your web host has disabled all functions for handling remote pages and as a result the BackLinks software will not function on your web page. Please contact your web host for more information.";
}



To display this, I need to assign a template value e.g. %%newcode%% to this piece of coding but no matter what I try it will not work. How do you wrap up the above text and assign $template['%%newcode%%'] to it?

This may seem like a basic question, but my programmer quit and I'm stuck until I can find a new one. The list of repairs/edits the last guy never did is huge and it's taking me forever because my PHP knowledge is very limited.

Thanks for your help
Mike

tangoforce
02-20-2012, 11:58 AM
Note that I'm using
tags..

[php]
function load_code()
{
return <<<'STOP'
//Insert PHP code here.
$OpenInNewWindow = "1";
$BLKey = "MFECU-J1BMR-TH1J7";
$QueryString = "LinkUrl=".urlencode((($_SERVER['HTTPS']=='on')?'https://':'http://').$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
$QueryString .= "&Key=" .urlencode($BLKey);
$QueryString .= "&OpenInNewWindow=" .urlencode($OpenInNewWindow);

if(intval(get_cfg_var('allow_url_fopen')) && function_exists('readfile')) {
@readfile("http://brokerage.linkadage.com/engine.php?".$QueryString);
}
elseif(intval(get_cfg_var('allow_url_fopen')) && function_exists('file')) {
if($content = @file("http://brokerage.linkadage.com/engine.php?".$QueryString))
print @join('', $content);
}
elseif(function_exists('curl_init')) {
$ch = curl_init ("http://brokerage.linkadage.com/engine.php?".$QueryString);
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_exec ($ch);

if(curl_error($ch))
print "Error processing request";

curl_close ($ch);
}
else {
print "It appears that your web host has disabled all functions for handling remote pages and as a result the BackLinks software will not function on your web page. Please contact your web host for more information.";
}
STOP;
}

$template['%%newcode%%'] = load_code();

instaunt
02-20-2012, 12:52 PM
Thank you tangoforce, but that just broke the page. Nothing would show user side.

Mike

tangoforce
02-20-2012, 01:25 PM
Turn on error reporting, show us the error message.



//Put this at the top of your script
ini_set('display_errors', 1);
error_reporting(E_ALL);

instaunt
02-20-2012, 02:53 PM
Sorry, I guess I don't understand. For error reporting I put:

ini_set ('display_errors', 1);
error_reporting(E_ERROR | E_WARNING | E_PARSE);

in the code and load. Obviously, nothing shows up just now because it's a blank page. How do I error report for scripts that won't even run?

Thanks
Mike

tangoforce
02-20-2012, 05:40 PM
Ok in that case you need to look at your error logs instead.

If that still doesn't give you any information then your PHP version might not be new enough to support the use of nowdoc.

Dormilich
02-21-2012, 07:36 AM
your PHP version might not be new enough to support the use of nowdoc.

the nowdoc syntax is supported since PHP 5.3.0



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum