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 3 of 3
  1. #1
    Regular Coder
    Join Date
    Sep 2002
    Location
    Saskatoon SK Canada
    Posts
    174
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question include get vars

    Is is possible to include a file and pass variables to it? I want to do this:
    PHP Code:
    <?php

    $product_id 
    $_GET['all_settings:product:code'];
    $category_id $_GET['all_settings:category:code'];
    $path_to_site $_SERVER['DOCUMENT_ROOT'] . '/Merchant2/product_include_files/also_suggest/';
    $also_suggest_filename =  $product_id '.php';
    $fallback_also_suggest_filename '_fallback_we_also_suggest.php';
    $my_vars_to_pass "?Current_Product_Code=" $product_id "&Category_Code=" $category_id;

    echo 
    '<div class="product_secondary_title" style="text-align:center;">We Also Suggest</div>';

    if (
    file_exists($path_to_site $also_suggest_filename)) {
        
    /*
        //product "we also suggest" area files to be uploaded to "/Merchant2/product_include_files/also_suggest/" and named the SKU.html example: VR-2CHPLANE.html
        //each product needs it's own file or the fallback file will be used.
        //do NOT include <html>, <head>, <meta>, <title>, <body>, <style> etc. tags in the html document. JUST THE HTML INFO TO BE DISPLAYED
        */
        
    include($path_to_site $also_suggest_filename $my_vars_to_pass);
    }
    else if (
    file_exists($path_to_site $fallback_also_suggest_filename)) { 
        
    /*
        //fallback file to default to until individual files are created
        */
        
    include($path_to_site $fallback_also_suggest_filename $my_vars_to_pass);
    }
    else { 
        
    // there is a problem because we haven't made our fallback file either!
        
    ?>
        <p>We have not populated our system for also suggested products yet. Please stay tuned.</p>
        <?php
    }

    ?>

    but I get this error.
    Warning: include(/var/www/localhost/htdocs/Merchant2/product_include_files/also_suggest/_fallback_we_also_suggest.php?Current_Product_Code=VR-2CHPLANE&Category_Code=RC_AIRPLANES_VORTEX) [function.include]: failed to open stream: No such file or directory in /var/www/localhost/htdocs/Merchant2/product_include_files/also_suggest/_default_display.php on line 24

    Warning: include() [function.include]: Failed opening '/var/www/localhost/htdocs/Merchant2/product_include_files/also_suggest/_fallback_we_also_suggest.php?Current_Product_Code=VR-2CHPLANE&Category_Code=RC_AIRPLANES_VORTEX' for inclusion (include_path='.:/usr/share/php5:/usr/share/php') in /var/www/localhost/htdocs/Merchant2/product_include_files/also_suggest/_default_display.php on line 24
    It works when I don't pass GET vars within the include part.

    I want to use the variables in my included documents that are created on the page that includes the document.
    Colin Puttick

  • #2
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    you don't need to pass them, just use them in the second file.

  • #3
    Regular Coder
    Join Date
    Sep 2002
    Location
    Saskatoon SK Canada
    Posts
    174
    Thanks
    2
    Thanked 0 Times in 0 Posts

    got it

    Awesome. For some reason I thought I had to pass them. It works now. I swear it didn't work like that before. Crazy. This works:

    PHP Code:
    <?php

    $product_id 
    $_GET['all_settings:product:code'];
    $category_id $_GET['all_settings:category:code'];
    $path_to_site $_SERVER['DOCUMENT_ROOT'] . '/Merchant2/product_include_files/also_suggest/';
    $also_suggest_filename =  $product_id '.php';
    $fallback_also_suggest_filename '_fallback_we_also_suggest.php';

    echo 
    '<div class="product_secondary_title" style="text-align:center;">We Also Suggest</div>';

    if (
    file_exists($path_to_site $also_suggest_filename)) {
        
    /*
        //product "we also suggest" area files to be uploaded to "/Merchant2/product_include_files/also_suggest/" and named the SKU.html example: VR-2CHPLANE.html
        //each product needs it's own file or the fallback file will be used.
        //do NOT include <html>, <head>, <meta>, <title>, <body>, <style> etc. tags in the html document. JUST THE HTML INFO TO BE DISPLAYED
        */
        
    include($path_to_site $also_suggest_filename);
    }
    else if (
    file_exists($path_to_site $fallback_also_suggest_filename)) { 
        
    /*
        //fallback file to default to until individual files are created
        */
        
    include($path_to_site $fallback_also_suggest_filename);
    }
    else { 
        
    // there is a problem because we haven't made our fallback file either!
        
    ?>
        <p>We have not populated our system for also suggested products yet. Please stay tuned.</p>
        <?php
    }

    ?>
    Thanks.
    Colin Puttick


  •  

    Posting Permissions

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