Page 1 of 1
Getting info inscript
Posted: Tue Jul 25, 2006 6:00 pm
by sabastious
How in php do you give a url in a script and get a response back IN the script that you can then set to a variable? if that makes sense
Thanks
Posted: Tue Jul 25, 2006 6:10 pm
by feyd
It's for a Query String
Posted: Tue Jul 25, 2006 6:15 pm
by sabastious
I dont have the code with me, but I did it in VBScript/ASP a while back. I ran a line of code that called a file somewhere out in the web. This file then ruturned a string of data only. I could take this data and place it into a variable, and parse it ect etc.
I used it when I was building a script to check whether a credit card was valid and whether the tranaction could be processed. I sent out the HTTP Request(I think thats what its called) and it sends back the response, and I never actually leave the script.
Can this be done in PHP?
Posted: Tue Jul 25, 2006 6:18 pm
by Luke
cURL can do that...
Posted: Tue Jul 25, 2006 6:24 pm
by sabastious
The Ninja Space Goat wrote:cURL can do that...
Sorry i'm new to PHP
What would be the syntax to grab the string sent back from
https://theurl.com/thefile.com?thevar=value ?
Using cURL of course.
I've been reading the docs, but they are not making a lot of sense to me

Posted: Tue Jul 25, 2006 6:28 pm
by Weirdan
IIRC:
Code: Select all
$cx = curl_init("https://theurl.com/thefile.com?thevar=value");
curl_setopt($cx, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($cx);
curl_close($cx);
Posted: Tue Jul 25, 2006 6:29 pm
by Weirdan
or just:
Code: Select all
$response = file_get_contents("https://theurl.com/thefile.com?thevar=value");
Posted: Tue Jul 25, 2006 6:41 pm
by sabastious
Worked, thank you so much!