...

View Full Version : include get vars



dreamingdigital
09-01-2006, 08:52 PM
Is is possible to include a file and pass variables to it? I want to do this:


<?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.:thumbsup:

GJay
09-01-2006, 08:55 PM
you don't need to pass them, just use them in the second file.

dreamingdigital
09-01-2006, 09:03 PM
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

$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.:cool:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum