receiving data....

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
matthiasone
Forum Contributor
Posts: 117
Joined: Mon Jul 22, 2002 12:14 pm
Location: Texas, USA
Contact:

receiving data....

Post by matthiasone »

Ok, here is the setup...I need to sent data via HTTP Post and receive a delimited string from a script. Is there anyway to do that in PHP? I have thought about cURL, but I couldn't find out if cURL can receive data.

Matt :?:
rev
Forum Commoner
Posts: 52
Joined: Wed Oct 02, 2002 3:58 pm
Location: Atlanta, GA

Re: receiving data....

Post by rev »

matthiasone wrote:Ok, here is the setup...I need to sent data via HTTP Post and receive a delimited string from a script. Is there anyway to do that in PHP? I have thought about cURL, but I couldn't find out if cURL can receive data.

Matt :?:
What you have described is basically submitting a form and abstracting a delimited string from data posted. Yes, PHP can do this.

If this is not what you are asking, then offer a bit more detail.
matthiasone
Forum Contributor
Posts: 117
Joined: Mon Jul 22, 2002 12:14 pm
Location: Texas, USA
Contact:

Post by matthiasone »

Well, maybe I not picking up on something, but from what I have been told and have read. I am getting a delimited string sent by directly to my script. What I am not sure about is how to receive and process that string. Here is part of documentation I have on the gateway info.
AIM Implementation
To implement AIM, a developer would design a script that does the following:
1. Securely obtains all of the information needed to process a transaction
2. Initiates a secure HTTPS form POST from their server to https://secure.authorize.net/gateway/transact.dll. Note: Authorize.Net will only accept transactions on port 443. This post will include all system variables mentioned in the tables below (see the following section entitled “Standard Transaction Submission API for AIM”).
3. Receives the response from the gateway and processes the response to display the appropriate result to the end user.
Hope this helps.

Matt
MeOnTheW3
Forum Commoner
Posts: 48
Joined: Wed Nov 13, 2002 3:28 pm
Location: Calgary, AB

Post by MeOnTheW3 »

Yes, you can get the returned info back.

I don't have the code in front of me, but I have integrated with UPS in the past, which required a HTTPS POST that returned a string.

I used cURL and accessed it by

Code: Select all

<?php
//- BUILD $command
//  Read the cURL documentation to get this right

$command = "complete HTTPS post head#CRLF#CRLF";
$command .= "all required stuff#CRLF";
$command .= "to be sent";


//- EXECUTE exec()
//  cURL doc's have info on the returned Status Codes of the execution
exec($command,$returnedStringAsArrayOfLines,$returnedStatusOfExec);
?>
It works very nicely.

Hope this helps, if you wish more help, just post what area you are having trouble with.
matthiasone
Forum Contributor
Posts: 117
Joined: Mon Jul 22, 2002 12:14 pm
Location: Texas, USA
Contact:

Post by matthiasone »

Well, that info at least show I am on the right track. But what I still would like to know is how to get the response string assigned to a variable. Any ideas.....none of the option for curl_setopt () have anything to do with recieving data back.
MeOnTheW3
Forum Commoner
Posts: 48
Joined: Wed Nov 13, 2002 3:28 pm
Location: Calgary, AB

Post by MeOnTheW3 »

If you use cURL to send a post, anything that is returned is captured in the second variable supplied in the exec() command. If it is multiple lines returned, the variable will be an array, else it will be a string.

So in:

exec($command,$returnedStringAsArrayOfLines,$returnedStatusOfExec);


the variable $returnedStringAsArrayOfLines will hold all data returned from the posted to uri.

In my case, i sent UPS an XML string and used the above mentioned method of attack and was returned an XML string back in the second var as shown above.

If this does not help, I will dig up my old code and make a more clear example.


Cheers
matthiasone
Forum Contributor
Posts: 117
Joined: Mon Jul 22, 2002 12:14 pm
Location: Texas, USA
Contact:

Post by matthiasone »

well what you are telling me is not matching the PHP Manual and other sources.
here is a example from the http://curl.haxx.se/libcurl/php/example ... lepost.php:

Code: Select all

<?php
//
// A very simple PHP example that sends a HTTP POST to a remote site
//

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,"http://www.mysite.com/tester.phtml");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "postvar1=value1&postvar2=value2&postvar3=value3");

curl_exec ($ch);
curl_close ($ch); 
?>

and here is one the manual says"
curl_exec -- Perform a CURL session
Description
bool curl_exec ( resource ch)


This function should be called after you initialize a CURL session and all the options for the session are set. Its purpose is simply to execute the predefined CURL session (given by the ch).

Tip: As with anything that outputs its result directly to the browser, you can use the output-control functions to capture the output of this function, and save it in a string (for example).
So I guess I am still not getting it....I understood what you are saying.....and hope you are right.......
MeOnTheW3
Forum Commoner
Posts: 48
Joined: Wed Nov 13, 2002 3:28 pm
Location: Calgary, AB

Post by MeOnTheW3 »

Let me find the code, I'll upload it make sense of it.

I understand your frustration. Took me awhile to figure it out, too.

The basics of it are that you do not need to use the php_built_in_cURL functions to activate and use cURL

Till I find my code, look at this: HTTPS Transactions via PHP

I only looked at it quickly, but it seems to explain in better detail than I am able to provide without my code.
matthiasone
Forum Contributor
Posts: 117
Joined: Mon Jul 22, 2002 12:14 pm
Location: Texas, USA
Contact:

Post by matthiasone »

MeOnTheW3, Thanks for the webpage. I managed to figure it out from that. THANK YOU! THANK YOU!!! :D
Post Reply