Solved

Association between website

Posted on 2011-09-26
5
187 Views
Last Modified: 2012-05-12
Hi,

I need to link from mysite to another website when a user is logged in, I'm wondering what the best way of doing this would be.

One thought that comes to mind would be to hold a identical SALT on both servers and pass as MD5 hash between via a link with a url, passing the user name too.

So somthing like:

$userid = "tom"
define('SALT','654gf4t5g6GTDY');
$hash = md5(SALT.$userid);

then on other end

define('SALT','654gf4t5g6GTDY');

if md5(SALT.$passedid) == $passedhash){
echo "link ok";
}

Open in new window


Is this the best way of doing it.

Darren
0
Comment
Question by:darren-w-
  • 3
  • 2
5 Comments
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 36598481
This kind of cross-site authentication makes some sense to me.  You might want to put it behind HTTPS just in case.
0
 
LVL 13

Author Comment

by:darren-w-
ID: 36598506
Thanks Ray, assuming the user will be logged in via https on my side, would the link to the external page need to be via https?
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 36598526
Yes, it could.  HTTPS is not required, it's just a good security precaution if you're going to be transferring any sensitive data between the sites.

The general design pattern might be a site-to-site handshake like the one illustrated here, adding your md5() string into the mix.
<?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'
, 'Richard' => 'Quadling'
, 'Dave'    => 'Baldwin'
)
;


// RESPONSE CAN BE PLAIN TEXT OR XML FORMAT
$alpha = NULL;
$omega = NULL;
if ( (isset($_GET["resp"])) && ($_GET["resp"] == 'XML') )
{
    // PREPARE THE XML WRAPPER
    $alpha = '<response>';
    $omega = '</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();
}



// LOOK UP 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
    echo $alpha . $dataModel[$name] . $omega;
    die();
}

// RETURNS THE UNKNOWN NAME INDICATOR
else
{
    echo $alpha . 'UNKNOWN' . $omega;
    die();
}

Open in new window

0
 
LVL 13

Author Closing Comment

by:darren-w-
ID: 36598556
Great thanks Ray
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 36598579
Thanks for the points - it's a great question. ~Ray
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
This video teaches users how to migrate an existing Wordpress website to a new domain.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question