Passing on values when opening a file with file()?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mikebr
Forum Contributor
Posts: 243
Joined: Sat Sep 28, 2002 7:05 am

Passing on values when opening a file with file()?

Post by mikebr »

I wonder if there is a way of passing on values when opening a file?

I have a script on a domain that does some calculations from the database on that domain, I access this script from another domain using the following code:

Code: Select all

$THE_STRING = file("http://domain/folder/php/get_data_calc.php?l=$l&d=$d&m=$m&y=$y");

$data_array = explode("|",$THE_STRING[0]);
print_r ($data_array);
The array $data_array returns the default values for the data as it does not pick up the variables passed in the URL, anyone know if there is a way of picking these passed variables up in get_data_calc.php?

I have tried using $_GET in the get_data_calc.php file but that does not work, also tried using
$theurl = $_SERVER['REQUEST_URI']; then breaking up $theurl to get the variable values but using $_SERVER['REQUEST_URI'] just stops the script from running in this case.

Do I have any other options on this?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

What does

Code: Select all

$source = "http://domain/folder/php/get_data_calc.php?l=$l&d=$d&m=$m&y=$y"
echo 'source: ', $source, "<br />\n";
$THE_STRING = file($source);

$data_array = explode("|",$THE_STRING[0]);
print_r ($data_array);
print?
mikebr
Forum Contributor
Posts: 243
Joined: Sat Sep 28, 2002 7:05 am

Post by mikebr »

volka,

I never even thought of doing it that way... is it not just basically the same thing?
anyway it seems to work so obviously not!

Many thanks
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

It only echos the url before passing it to file() - for debug purposes. It fixes nothing.
mikebr
Forum Contributor
Posts: 243
Joined: Sat Sep 28, 2002 7:05 am

Post by mikebr »

Puzzeled, this does not work:

Code: Select all

$THE_STRING = file("http://domain/folder/php/get_data_calc.php?l=$l&d=$d&m=$m&y=$y"); 

$data_array = explode("|",$THE_STRING[0]); 
print_r ($data_array);
but this does:

Code: Select all

$SOURCE = "http://domain/folder/php/get_data_calc.php?l=$l&d=$d&m=$m&y=$y"; 

$THE_STRING = file($SOURCE);

$data_array = explode("|",$THE_STRING[0]); 
print_r ($data_array);
?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

a miracle.
Post Reply