Jump to content

Recommended Posts

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

 

 

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.

 

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

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.