Getting info inscript

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
sabastious
Forum Newbie
Posts: 8
Joined: Thu Jul 20, 2006 6:09 pm

Getting info inscript

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

sabastious
Forum Newbie
Posts: 8
Joined: Thu Jul 20, 2006 6:09 pm

It's for a Query String

Post 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?
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

cURL can do that...
sabastious
Forum Newbie
Posts: 8
Joined: Thu Jul 20, 2006 6:09 pm

Post 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 :(
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post 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);
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

or just:

Code: Select all

$response = file_get_contents("https://theurl.com/thefile.com?thevar=value");
sabastious
Forum Newbie
Posts: 8
Joined: Thu Jul 20, 2006 6:09 pm

Post by sabastious »

Worked, thank you so much!
Post Reply