Fallen_angel Posted May 10, 2007 Share Posted May 10, 2007 Hi , I am hopign someon can help me out here I am trying to use the following include include "./file.php?foo=var1&bar=var2" ; However its not working because the server is obiously looking for a file called "file.php?id=var1&bar=var2" not just file.php then parsing the variables to it. I have read a few peoples sugestions in the includes manual liek settign the variable outside of the include and then passing it into the include itself ie $vars= '?foo=var1&bar=var2' ; include './file.php$vars ; : but that did what i thought it would and just spat back the same error. I am sure it's the variable thats causign the issue because when i take it away the include works however this makes it so that my script doesn't work properly without manually setting the variable Thanx to anyone that can help out Quote Link to comment https://forums.phpfreaks.com/topic/50750-problem-parsing-variables-in-php-include-please-help/ Share on other sites More sharing options...
btherl Posted May 10, 2007 Share Posted May 10, 2007 Try this: $foo=$var1; $bar=$var2; include "./file.php"; $foo and $bar will be available inside file.php Quote Link to comment https://forums.phpfreaks.com/topic/50750-problem-parsing-variables-in-php-include-please-help/#findComment-249505 Share on other sites More sharing options...
yzerman Posted May 10, 2007 Share Posted May 10, 2007 This is the example your looking for: <?php /* This example assumes that www.example.com is configured to parse .php * files and not .txt files. Also, 'Works' here means that the variables * $foo and $bar are available within the included file. */ // Won't work; file.txt wasn't handled by www.example.com as PHP include 'http://www.example.com/file.txt?foo=1&bar=2'; // Won't work; looks for a file named 'file.php?foo=1&bar=2' on the // local filesystem. include 'file.php?foo=1&bar=2'; // Works. include 'http://www.example.com/file.php?foo=1&bar=2'; $foo = 1; $bar = 2; include 'file.txt'; // Works. include 'file.php'; // Works. ?> If your going to include a file, with ?foo=1&bar=2, you need to use an absolute path. Quote Link to comment https://forums.phpfreaks.com/topic/50750-problem-parsing-variables-in-php-include-please-help/#findComment-249507 Share on other sites More sharing options...
Fallen_angel Posted May 10, 2007 Author Share Posted May 10, 2007 Try this: $foo=$var1; $bar=$var2; include "./file.php"; $foo and $bar will be available inside file.php This is the example your looking for: Code: <?php /* This example assumes that www.example.com is configured to parse .php * files and not .txt files. Also, 'Works' here means that the variables * $foo and $bar are available within the included file. */ // Won't work; file.txt wasn't handled by www.example.com as PHP include 'http://www.example.com/file.txt?foo=1&bar=2'; // Won't work; looks for a file named 'file.php?foo=1&bar=2' on the // local filesystem. include 'file.php?foo=1&bar=2'; // Works. include 'http://www.example.com/file.php?foo=1&bar=2'; $foo = 1; $bar = 2; include 'file.txt'; // Works. include 'file.php'; // Works. ?> If your going to include a file, with ?foo=1&bar=2, you need to use an absolute path. Thankyou both very much , thats is exactly what i was tryign to go through but it wasn't workign for me however yes the full path was working but not apropriate for the situation this script is setup in unfortunatly. I have ended up goign with $_GET['id]=foo ; include "file.php" ; then on the other page i simply pulled the get vairable out and it works wonderfully thankyou both so so much again Quote Link to comment https://forums.phpfreaks.com/topic/50750-problem-parsing-variables-in-php-include-please-help/#findComment-249517 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.