Link to home
Start Free TrialLog in
Avatar of mssky
msskyFlag for Austria

asked on

Communication between to different web applications/domains

I’m looking for a solution that allows communication between two different web applications.
I’ve been thinking about Web Service already, but I’m not certain if that is the right approach.
Here’s what I need to do:
-      Communicate/request information from a remote web application
-      Retrieve and process the response serverside (invisibel for the user)
-      Output the result on my web application or reqeust again from the remote web application.

All this needs to be done via web browser.

Could you please point me in the right direction.
Thanks in advance.
Avatar of Robert Saylor
Robert Saylor
Flag of United States of America image

You will run into issues with sessions because sessions are stored on the 1 domain only. You could pass parameters to the remote website but the best way is to store data in a database and then encrypt your parameters to the remote website having the remote web site decrypt the parameters to retrieve the data from a database that is setup to accept remote connections.
ASKER CERTIFIED SOLUTION
Avatar of Mark Brady
Mark Brady
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@ rsaylor  
I use database session handling for that sort of thing. I was going to use php database session handling but it was to restrictive/limited for my needs so I built my own session handler.

Basically instead of doing a session_start()  you instantiate the session class (which I built).

The constructor looks for a session cookie with a certain name and if it finds it it loads the cookie data which is an id of that session. Then it loads all the session variables from the database with that session id into an object or an array which you make global to your private/public functions in the class.

Each session has an expiry time and when a request is made for any session, it checks the expiry time and if it has expired it is deleted along with any session data records.
Nice send the code if you don't mind. That could be really handy.
In case anyone suggests that you use SOAP, run (don't walk) for the exits.  The web is littered with the rotting and dessicated carcasses of failed SOAP projects, and it is now almost universally avoided in favor of simpler and more intuitive web service protocols.  A RESTful web service is probably the right way to go.  REST uses the design of the WWW.  Requests are atomic, complete and stateless; responses are complete and usually instantaneous.  Please read this article for some background on the client/server model.
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/A_11271-Understanding-Client-Server-Protocols-and-Web-Applications.html

The code snippet shows the "hello world" exercise for a RESTful web service.  Because it is an information-only service, it uses the GET method for requests and it can be tested from the web browser address bar.  This makes the process of modifying and debugging amazingly quick and easy.  You can experiment with it on my server via this URL.
http://www.laprbass.com/RAY_REST_get_last_name.php?key=ABC&resp=&name=COBOL

<?php // RAY_REST_get_last_name.php
error_reporting(E_ALL);


// DEMONSTRATE HOW A RESTFUL WEB SERVICE WORKS
// INPUT FIRST NAME, OUTPUT FAMILY NAME
// CALLING EXAMPLE:
// file_get_contents('http://laprbass.com/RAY_REST_get_last_name.php?key=ABC&resp=XML&name=Ray');


// OUR DATA MODEL CONTAINS ALL THE ANSWERS - THIS COULD BE A DATA BASE - AS SIMPLE OR COMPLEX AS NEEDED
$dataModel
= array
( 'Brian'   => 'Portlock'
, 'Ray'     => 'Paseur'
, 'COBOL'   => 'Dinosaur'
, 'Dave'    => 'Baldwin'
)
;


// RESPONSE CAN BE PLAIN TEXT OR XML FORMAT
$alpha = NULL;
$omega = NULL;

// NORMALIZE AND TEST THE "resp=" ARGUMENT
if ( (isset($_GET["resp"])) && (strtoupper(trim($_GET["resp"])) == 'XML') )
{
    // PREPARE THE XML WRAPPER
    $alpha = '<?xml version="1.0" encoding="utf-8" ?>' . PHP_EOL . '<response>' . PHP_EOL;
    $omega = PHP_EOL . '</response>';
}


// TEST THE 'API KEY' - THIS COULD BE A DATA BASE VALIDATION LOOKUP - AS SIMPLE OR COMPLEX AS NEEDED
$key = (!empty($_GET["key"])) ? $_GET["key"] : FALSE;
if ($key !== 'ABC')
{
    echo $alpha . 'BOGUS API KEY' . $omega;
    die();
}


// LOOKUP THE FAMILY NAME
$name = (!empty($_GET["name"])) ? $_GET["name"] : 'UNKNOWN';

// IF THE NAME FROM THE URL IS FOUND IN THE DATA MODEL
if (array_key_exists($name, $dataModel))
{
    // RETURNS THE APPROPRIATE FAMILY NAME FROM THE DATA MODEL
    die( $alpha . $dataModel[$name] . $omega );
}


// RETURNS THE UNKNOWN NAME INDICATOR
else
{
    die( $alpha . "UNKNOWN: $name" . $omega );
}

Open in new window

Best regards, ~Ray
Actually I can post it as I wrote it for my company and that would cost me my job unfortunately. However the basic principles are quite straight forward to implement.
Avatar of mssky

ASKER

Thanks to all for you prompt replay.
B grade?  Nice.