Page 1 of 1

file_get_contents with a variable

Posted: Wed Jun 07, 2006 6:23 pm
by computerwiz3491
I am trying to display another page. I also want a variable in the URL.

Code: Select all

$site=file_get_contents("test.php?id=$id");
This gives me Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/content/q/a/z/qazwart/html/daniel/php/survey2.php on line 44

I also tried

Code: Select all

$page="test.php?id=$id";
$site=file_get_contents("$page");
This gives me the same error. Any ideas?

Thanx.

Posted: Wed Jun 07, 2006 6:27 pm
by PrObLeM
can we see the whole code? The error may not be there.

Posted: Wed Jun 07, 2006 6:30 pm
by computerwiz3491
The problem only exists if I have a variable in the file_get_contents.

Code: Select all

file_get_contents("test.php?id=billy");
gives me no problems

Posted: Wed Jun 07, 2006 6:35 pm
by Christopher
The question is why you want to do what you are trying to do? The function you are using loads the contents of a file into a variable. You are adding URL parameters to a filesystem call -- which will just give you file name errors.

So let us in on the big secret ... what is your goal here?

Posted: Wed Jun 07, 2006 6:38 pm
by computerwiz3491
I am trying to make a page display if certain conditions are met. I want the url of the accual page to stay hidden from the untrained eye. I am using a print statement to display the page. It works fine as long as I don't want to put a variable as the URL

Posted: Wed Jun 07, 2006 6:44 pm
by nathanr
you could try this:

Code: Select all

$page="test.php?id=".trim($id); 
$site=file_get_contents($page);

Posted: Wed Jun 07, 2006 6:44 pm
by PrObLeM
why not just

Code: Select all

<?php
     include("test.php?id=$id");
?>

Posted: Wed Jun 07, 2006 6:48 pm
by computerwiz3491
why not just

Code: Select all

<?php
     include("test.php?id=$id");
?>
I don't want to just include the file because test.php is extreamly complex and does different things depending on how it's opened.[/quote]

Posted: Wed Jun 07, 2006 7:16 pm
by nathanr
header redirect or combine the scripts to

Code: Select all

if ($conditionmet) {
  //test.php code here
} else {
  //normal code here
}
i don't quite understand the way your doing it but.. (or indeed why that way)

Posted: Wed Jun 07, 2006 7:43 pm
by computerwiz3491
If I use an include() I get the same error when I use a variable.

Posted: Thu Jun 08, 2006 4:35 am
by nathanr
try commenting out the line that pulls in the page, see if you still get the error....