php file_get_contents()

  • smiledrops
  • Student
  • Student
  • User avatar
  • Posts: 66
  • Loc: pakistan

Post 3+ Months Ago

is it possible to get a variable value after use of file_get_content() function (PHP).

for example:
i use
Code: [ Select ]
$show_cc = file_get_contents("http://www.myothersite.com/getfile.php");


in current file (current.php)

i have declared a variable named as $thisVar in getfile.php

now i use this ($thisVar) value in current.php

hopefully u understand what i need...

any help would be appriciated...
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13504
  • Loc: Florida

Post 3+ Months Ago

Only if the file you include outputs something that the script can interpret as a variable value.

Any time you refer to a PHP page using http:// be it through include or file_get_contents, the variables have already resolved and the only thing available is the output.
  • Bozebo
  • Expert
  • Expert
  • User avatar
  • Posts: 709
  • Loc: 404

Post 3+ Months Ago

smiledrops wrote:
is it possible to get a variable value after use of get_file_content() function (PHP).

for example:
i use
Code: [ Select ]
$show_cc = get_file_contents("http://www.myothersite.com/getfile.php");


in current file (current.php)

i have declared a variable named as $thisVar in getfile.php

now i use this ($thisVar) value in current.php

hopefully u understand what i need...

any help would be appriciated...


just use include, but you must be in the same webspace as getfile.php and refer to it's path
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8416
  • Loc: USA

Post 3+ Months Ago

I've got a few things to say.

1) It's not get_file_contents()... its file_get_contents()
2) file_get_contents() stores the contents of the file to a variable...
3) include() would work much better for you... as it includes the file into another file rather then storing the contents of that file into a variable.
  • smiledrops
  • Student
  • Student
  • User avatar
  • Posts: 66
  • Loc: pakistan

Post 3+ Months Ago

ok thx for the responses....

i have used include and require also, it works (no errors) but i can't get the variables value on current.php ??

is there any solution for doing this ???
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13504
  • Loc: Florida

Post 3+ Months Ago

No there's not.

If it was possible, I could just include the config files from sites all over the internet and steal their database passwords.

If these sites are on the same server, you can enter the exact path to the file, which will not start with http://
Otherwise you're out of luck.
  • smiledrops
  • Student
  • Student
  • User avatar
  • Posts: 66
  • Loc: pakistan

Post 3+ Months Ago

ok. let say my domain names are

http://www.xyz.com
http://www.abc.xyz.com

then what is the case ??

is it possible to restrict the requests to http://www.abc.xyz.com other then http://www.xyz.com...


actually i have stored some files on http://www.abc.xyz.com and wish request only comes from http://www.xyz.com execute otherwise some message displayed...........

is it possible using HTACCESS, i have tried it too but no succeed...

any help now ???/
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13504
  • Loc: Florida

Post 3+ Months Ago

It does not make any difference whatsoever what the domain names are.
The two sites must be on the same filesystem if you want access to variables. If your include path will begin with "http://" the answer will always be no with no exceptions if you want access to variables.

If you're just interested in the computed output of the file and not the variables, you can include a file from a path starting with "http://" and get the computed output.
Access to the file when accessed in that way can be restricted to certain sources in htaccess by using Apaches Access Control and a <files> container.
  • smiledrops
  • Student
  • Student
  • User avatar
  • Posts: 66
  • Loc: pakistan

Post 3+ Months Ago

thank u for ur wise replies....

but can u help me regarding htaccess, so that request only accepted from http://WWW.XYZ.COM to http://WWW.ABC.XYZ.COM ??

please......
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13504
  • Loc: Florida

Post 3+ Months Ago

If those links to the Apache manual don't help, I'm not going to be able to explain it any better.

Post Information

  • Total Posts in this topic: 10 posts
  • Users browsing this forum: No registered users and 44 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.