FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


File_get_contents and url query strings





richard270384
Hi,

I use file_get_contents in a number of different ways on my site.

In this particular instance i'm using file_get_contents to open a php file on my website, and indexing it's content for my search script.

I have always used file_get_contents with a URL rather than file reference becuase I always get errors when I try and reference the file directly.

Code:
E.g.

I use
file_get_contents("http://www.music-whiz.com/filename.php?arg1=something")

Instead of
file_get_contents("filename.php?arg1=something")


It does make sense to my why referencing the file directly does not work when there is a query string after it, so does anybody know how I can get something that essentially does the same thing?

Everytime my server admin does any sort of update, allow_url_fopen gets turned off and some of my scripts die. It's easy enough to get it turned back on but it's very annoying.
Stubru Freak
richard270384 wrote:
Hi,

I use file_get_contents in a number of different ways on my site.

In this particular instance i'm using file_get_contents to open a php file on my website, and indexing it's content for my search script.

I have always used file_get_contents with a URL rather than file reference becuase I always get errors when I try and reference the file directly.

Code:
E.g.

I use
file_get_contents("http://www.music-whiz.com/filename.php?arg1=something")

Instead of
file_get_contents("filename.php?arg1=something")


It does make sense to my why referencing the file directly does not work when there is a query string after it, so does anybody know how I can get something that essentially does the same thing?

Everytime my server admin does any sort of update, allow_url_fopen gets turned off and some of my scripts die. It's easy enough to get it turned back on but it's very annoying.


The first code gets your page over HTTP, just like you would.
The second just gets the source code of the file, like you get when opening a local file. You could tell PHP to parse it with eval, or a shell command.
richard270384
Yeah, I never thought of using eval.

But since my pages rely on recieving variables by $_GET or $_POST, how could I send variables to the script before I eval it?

I'm thinking I could create an array (I'll call it $args) and store the variables that I would have sent in the url in that array, then do a str_replace on the code before I eval() it, replacing all instances of $_GET and $_POST with $args.

Do you think that would work? Or is there an easier way?

Cheers,
Richard
kv
An easier way is to write a wrapper script in which you create $_GET array and store your args in, then read the original script and eval.

Then you can call the wrapper script locally (client call instead of http).
richard270384
For some reason, I assumed $_GET was read only and couldn't be set. I guess I was wrong - if I can set $_GET myself then I don't really have any problems.

Cheers,
Richard
phpc0d3r
Nope you can set $_GET array to anything.
But you really shouldn't unset it Embarassed (bad experience doing that once).

for instance you can set $_GET as an empty array:
Code:

$_GET = array();
$_POST = array();

heck even:
$_SERVER = array(); //Security Conscious Fiends

It helps secure scripts when you have the variables you need. (But that's not a guaranteed way).
Related topics
very simple PHP code to get search query string
mod_rewrite
75FRIH$ Mod_Rewrite Code
Is this code safe, or not?
PRECISO DE UM CODIGO DE BUSCA INTERNA EM HTML
How to have two domains for the same site
Help needed link/page checker
Hacked by someone sql Injection
Uploading Files to the Database
Getting PHP variable to work in FCKeditor
How do I escape an ampersand in a url?
Get html code from an extrenal url
jQuery AJAX Methods
Web Page Scrapper
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.