kc8yds
06-10-2007, 03:18 PM
Hi,
I have been working on an idea to allow 2 different domains that I have to run as one, and use on database for the both as well as only needing to login once, and allow the user info to work for both domains.
basically what I came up with, is the following. This is just for example purposes the real thing does validation on the password on the first page, then the second validates the value of GET-hash is correct, before setting it as a cookie.
domain1.com/login.php
<?
if(!isset($_COOKIE['user'])){
for($i=0;$i<='99';$i++){$hash .= rand(1, 9);}
setcookie("user", "$hash", time()+3600);
header('Location: http://domain2.com/login.php?hash='.$hash);
}else{
?>
<?=$_COOKIE['user'];?>
<? }
?>
domain2.com/login.php
<?
if(isset($_GET['hash'])){
setcookie("user", "$_GET[hash]", time()+3600);
header('Location: http://domain1.com/login.php');
}else{
?>
<?=$_COOKIE['user'];?>
<? }
?>
it basically uses a header redirect to redirect to the other domain with the value of the cookie set as part of the url then redirects back to the original site, now each domain name has its own cookie with the user info.
before actually putting this to use on the site, I would like some input as to if it would be secure to use this or not.
thanks.
I have been working on an idea to allow 2 different domains that I have to run as one, and use on database for the both as well as only needing to login once, and allow the user info to work for both domains.
basically what I came up with, is the following. This is just for example purposes the real thing does validation on the password on the first page, then the second validates the value of GET-hash is correct, before setting it as a cookie.
domain1.com/login.php
<?
if(!isset($_COOKIE['user'])){
for($i=0;$i<='99';$i++){$hash .= rand(1, 9);}
setcookie("user", "$hash", time()+3600);
header('Location: http://domain2.com/login.php?hash='.$hash);
}else{
?>
<?=$_COOKIE['user'];?>
<? }
?>
domain2.com/login.php
<?
if(isset($_GET['hash'])){
setcookie("user", "$_GET[hash]", time()+3600);
header('Location: http://domain1.com/login.php');
}else{
?>
<?=$_COOKIE['user'];?>
<? }
?>
it basically uses a header redirect to redirect to the other domain with the value of the cookie set as part of the url then redirects back to the original site, now each domain name has its own cookie with the user info.
before actually putting this to use on the site, I would like some input as to if it would be secure to use this or not.
thanks.