Forum Moderators: coopster

Message Too Old, No Replies

Quick question regarding php function

function

         

jmayerfan

1:41 am on Sep 5, 2008 (gmt 0)

10+ Year Member



Is it possible to write a php function (not javascript / not ajax) that will query a remote url with a parameter? I.E. writing a function that would look something like function(url, param) from a web form and actually query the url with the parameter?

I've coded a php page to do this with a web form (post variables, get variables, perform search from url). Could it be done with just a php function though?

I'm thinking something along the lines of:
function ($url,$param)
{
if(!$params) return $url;
$tempurl = $url
if(strpos($tempurl,'?') === false) $tempurl .= '?'; //Adds ? to end if not exist.
$newresult = $tempurl .'test_string=' . $query;

//This would output newresult as something along the lines of "http:www.url.com?test_string=paramcontents"

//Then perform the query on the url.

}

Since php is server side I don't think it could be done.

eelixduppy

1:52 am on Sep 5, 2008 (gmt 0)



If it's using GET then you can just use something like file_get_contents [php.net] to grab the generated page. If you want to POST variables, then you can use cURL [php.net].

And Welcome to Webmaster World! :)

jmayerfan

1:56 am on Sep 5, 2008 (gmt 0)

10+ Year Member



Yeah but will either of those push form data to a remote host. I also know that cURL might not be available on all php servers. Basically, I'm just looking for something that can be provided a url and a parameter and have the url host be queried with the parameter.

Also, am I alone here in the idea that simply coding a form to pass the parameters is alot more efficient?

And thanks! Pretty cool place.

jmayerfan

5:29 am on Sep 5, 2008 (gmt 0)

10+ Year Member



Anybody else? What if I just pushed the string via a header("location=$newresult") call. This would do the same thing as a form push wouldn't it?

jmayerfan

7:58 am on Sep 5, 2008 (gmt 0)

10+ Year Member



This thread can be locked I've figured it out

coopster

1:39 pm on Sep 5, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



What was your solution?