Computing.Net > Forums > Web Development > PHP -Processing server confirmation

PHP -Processing server confirmation

Reply to Message Icon

Original Message
Name: wizard-ict
Date: March 8, 2005 at 17:06:02 Pacific
Subject: PHP -Processing server confirmation
OS: linux
CPU/Ram: unspecified
Comment:

Hi Guys.
I need some help with this one!
I am developing a PHP script to communicate with an Automatic Payment Confirmation server (Nochex).
Basically the the server sends me customer details, I check them and POST them back (I believe I have this part working using 'fsockopen' etc).
The server then responds with a single word in the body (Accept or Decline), this is the part I am having problems with. I have know idea how to read or save this response. Ideally I would save it to a file, but as it is not a variable passed by either POST or GET i don't know how.
Nochex only work with .asp so can't help me with a PHP version.
Anyone got any ideas? If it helps anyone here is the .asp code they suggest using (I use a linux server which can't handle asp and have no knowledge of it so it means very little to me!!).

if (objHttp.status = 200 ) then
if (objHttp.responseText = "AUTHORISED") then NochexResponse = "AUTHORISED"
'process transaction
elseif (objHttp.responseText = "DECLINED") then
NochexResponse = "DECLINED"
'log and investigate incorrect data
end if
else
NochexResponse = "NO RESPONSE "
end if

%>


Wizard ICT. Microsoft Certified Professional



Report Offensive Message For Removal

Response Number 1
Name: anonproxy
Date: March 9, 2005 at 23:23:59 Pacific
Subject: PHP -Processing server confirmation
Reply: (edit)

"this is the part I am having problems with."

The ASP code is hiding a lot of details. I believe objHttp.responseText is a simple return of the received plaintext from the stream. That is, that objHttp.responseText includes everything minus the header. Therefore, if the document has only one word, it will show in here. I am assuming this - check an ASP object tree for the details.

Let's assume I am right. What you can do is write to the resource handle which fsockopen() returns and then immediately afterwords check that resource handle for results with fgets().

For example:

$fp = fsockopen ('www.domain.tld', 80, $errno, $errstr, 30);

$fp is our file pointer - in this case it goes to a socket. So far, we have opened a socket, a connection. Now let's write to it with fputs():

fputs ($fp, $header . $token);

fputs() is also fwrite(). $header is an http header as a string and $token is an authentication key (which is a common practice, not sure if it applies to your situation).

Here we are writing to a file pointer, which is connected to a stream. Behind the scenes, the webserver should respond and write something to the other end of $fp. We can of cource check $fp to see if this has occured.


fputs($fp, $something_to_send);
while (!feof($fp)) {
$response .= fgets($fp);
}
fclose($fp);

Here we have sent some data (a header in your case) and are checking the socket stream for return data. We read this data with fgets and write to $response. This is a loop, so don't leave out the concat operator on $response.

From here, you can search $response multiple ways, for example by exploding it into an array and looping through that or with a regular expression.

Check out the PHP online manual - especially the comments section. There is a lot of useful code in there, practically for every function.


Report Offensive Follow Up For Removal

Response Number 2
Name: wizard-ict
Date: March 10, 2005 at 12:24:47 Pacific
Subject: PHP -Processing server confirmation
Reply: (edit)

Thanks for your help, I have it up and running now.
I had most of the code you outlined in place, what I wasn't aware of is that the response could be checked with fgets and written to my script (the last part of your code).
My PHP is still a bit sketchy as I have been teaching myself as I go along so I don't always understand exactly what every part is doing.
For this reason your explaination was very useful as you detailed each section. Thanks for you help.

Wizard ICT. Microsoft Certified Professional


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: PHP -Processing server confirmation

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software