Page 1 of 1

PHP Website communication with other Website

Posted: Fri Jul 21, 2006 9:43 am
by phpthebest
Hi Everybody,

Does anyone know that how to communicate with otherwebsite. My website which is using PHP and MySQL, needs to communicate with other website.

The Other wibsite will need to send certain parameters, e.g. (username, password, code), my website will check for the information in the local database and send value back YES/NO (if code found again that username, password then yes otherwise no).

My question is how my website can efficiently handle this. Do I need to write some API if yes, any example, any hint.

I know other website will submit request to some URL on my website along with the parameters. My website will receive request and find the results from the database, Now how I need to send answer (YES/NO) back to otherwebsite efficiently?


Thanks

Posted: Fri Jul 21, 2006 10:20 am
by Burrito
you could do this with cURL or XML.

I think for simplicity's sake, I'd pick cURL. one web site could post data to the other then deal with the response accordingly.

Posted: Fri Jul 21, 2006 10:40 am
by onion2k
Pegleg Jackson wrote:you could do this with cURL or XML.

I think for simplicity's sake, I'd pick cURL. one web site could post data to the other then deal with the response accordingly.
If the other website is POSTing the data to phpthebest's site, then they'll be the ones using cURL, not phpthebest. His site just needs a normal PHP form handler.

Posted: Fri Jul 21, 2006 10:52 am
by phpthebest
Pegleg Jackson wrote:you could do this with cURL or XML.


I think for simplicity's sake, I'd pick cURL. one web site could post data to the other then deal with the response accordingly.
Thanks for the quick reply.

As I know, if I use cURL, I need to send query string (YES/NO) to other websites URL.
e.g.

http://www.otherwebsiteabc.com/abc.php?answer=yes
http://www.otherwebsiteabc.com/abc.php?answer=no

So other website need to catch data from abc.php from parameters.



Is there any other way to handle that, e.g. otherwebsite/application call to my site as follows, and it will return result from my website (YES/No) to variable. Something as described below:

Other website/application send data to my website using some function and get result into get_answer.

get_answer = get_data(username, password, code);


Thanks.

Posted: Fri Jul 21, 2006 3:57 pm
by Burrito
you can post data using cURL. YOu don't have to send the params as $_GET params.

the alternative would be to use XML and have the servers reach out for new info vs pushing info from one another.

Posted: Fri Jul 21, 2006 4:45 pm
by onion2k
Why are people suggesting cURL? He'll only need cURL if he's pushing POST data out to the other site .. he isn't. The other site is POSTing data to a PHP script on his site, and he's returning text. Something as simple as..

Code: Select all

<?php

$user = $_POST['user'];
$pass = $_POST['pass'];

if ($user=="Womble" && $pass=="wimbledon") {
  echo "Yes";
} else {
  echo "No";
}

?>
..will work. Might need to do header("Content-type: text/plain"); at the top but that's not strictly necessary.

It's exactly the same as any normal browser request as far as he's concerned.