http_get() or something similar?
Author |
Message |
canuckster
|
Posted: Sat Mar 24, 2007 5:47 pm Post subject: http_get() or something similar? |
|
|
I'd like to know how to send a GET string to a url via PHP without having to open up a window for it.
I have a Flash-based order form that fires off data to a PHP script; this script interacts with the database, sends a couple of emails, and throws back a confirmation to Flash that all went well. Now I need to register the sale with an external site. To do that, I need to invoke a URL with a GET string, ie:
www.othersite.com/salestracker/?clientID=12345&orderValue=19.99 -- something like that.
After some research, it seems PHP has an optional PECL library which contains a ton of HTTP-related functionality, including a function called http_get(), but this library isn't part of the default installation on my site (shared hosting).
Is there another way of accomplishing this? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
PaulButler
|
Posted: Sat Mar 24, 2007 8:30 pm Post subject: RE:http_get() or something similar? |
|
|
Well, first of all, this is not a secure way of doing things. Anyone who knew the URL could wreck havoc by making fake orders and stuff.
That said, there are a few ways to do an HTTP request in PHP. By far the easiest is:
php: |
$result = file_get_contents('www.othersite.com/salestracker/?clientID=12345&orderValue=19.99');
|
If you are on a shared host, note that some servers disable this for security reasons.
If you need more precise control, you can use CURL (see the PHP manual for more information) if your server has it. |
|
|
|
|
|
canuckster
|
Posted: Sun Apr 01, 2007 10:45 pm Post subject: Re: http_get() or something similar? |
|
|
Paul,
Thanks for the reply. I didn't happen to notice it till just now because I didn't subscribe to the thread (though I'd meant to).
I agree the method isn't very secure, though in fact it doesn't actually register orders, but is used to track affiliates (we assign you affiliate code 1234, then when one of our customers buys something and enters your code, you get a cut of the deal). And in any case, we don't have a choice, since this is how the company we're working with (that manages all the affiliate tracking) does things ...
Anyway, I found a solution. I reasoned that I could invoke the URL simply by using it as an img src. This worked when I tried it in a php page, but I had an additional challenge in that I wasn't directly invoking the php page, but was instead sending and retrieving data to it from a Flash form (when Flash invokes an active page, whatever text that page would normally output to the browser is instead sent to Flash to parse); obviously, sending an image's url was not the same as actually trying to display it.
So instead, I reprogrammed the php page to send back to Flash the variables that would be required to assemble the URL; upon receiving this, Flash then tries to load a movie using this URL, thus invoking it as originally desired. Worked like a charm.
I originally wanted to add the PECL library to use http_get(), but it wasn't an option in my shared hosting environment. I'll ask them about the method you suggested -- I'd rather keep everything within PHP. |
|
|
|
|
|
canuckster
|
Posted: Thu Apr 19, 2007 12:18 am Post subject: RE:http_get() or something similar? |
|
|
Just wanted to add, Paul, that this issue came up for me again this week -- but from a completely different source.
We changed credit card processers; whereas the old one had accepted an XML string and sent back a response -- something Flash was well suited to work with -- the new one used an ASP page that was supposed to behave the same way but didn't (I think it called some kind of refresh which made Flash think it was finished before any variables had been returned). Anyway, the point was it didn't work!
So, remembering your post, I tried an approach where Flash called a PHP page that in tuen called file_get_contents () on the ASP page, and then finally echoed whatever the ASP page returned. Worked great -- and saved my @ss in a big way.
Thanks again for your suggestion. |
|
|
|
|
|
PaulButler
|
Posted: Thu Apr 19, 2007 6:48 am Post subject: RE:http_get() or something similar? |
|
|
Cool, I'm glad it worked. |
|
|
|
|
|
|
|