Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Apr 2010
    Posts
    125
    Thanks
    6
    Thanked 0 Times in 0 Posts

    How do you wrap up a piece of code to insert?

    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:


    PHP Code:
    $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 ($chCURLOPT_HEADER0);
        
    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
    Last edited by instaunt; 02-20-2012 at 12:51 PM.

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,476
    Thanks
    63
    Thanked 538 Times in 525 Posts
    Note that I'm using [php] tags..

    PHP Code:
    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 ($chCURLOPT_HEADER0);
    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(); 
    I can't really think of anything to write here now...

  • #3
    Regular Coder
    Join Date
    Apr 2010
    Posts
    125
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Thank you tangoforce, but that just broke the page. Nothing would show user side.

    Mike

  • #4
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,476
    Thanks
    63
    Thanked 538 Times in 525 Posts
    Turn on error reporting, show us the error message.

    PHP Code:
    //Put this at the top of your script
    ini_set('display_errors'1);
    error_reporting(E_ALL); 
    I can't really think of anything to write here now...

  • #5
    Regular Coder
    Join Date
    Apr 2010
    Posts
    125
    Thanks
    6
    Thanked 0 Times in 0 Posts
    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

  • #6
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,476
    Thanks
    63
    Thanked 538 Times in 525 Posts
    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.
    I can't really think of anything to write here now...

  • #7
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,474
    Thanks
    13
    Thanked 361 Times in 357 Posts
    Quote Originally Posted by tangoforce View Post
    your PHP version might not be new enough to support the use of nowdoc.
    the nowdoc syntax is supported since PHP 5.3.0
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •