|
Implementing Cross-Domain Cookies
Step 1: Setting Up A Prepend Script
Add the following code to a prepend script (or a function that appears at the top
of all scripts).
<?php
/* Support cross-domain cookies... */
// If the GET variable has been set, and it differs from the cookie
// variable, then use the get variable (and update the cookie)
global $HTTP_COOKIE_VARS, $HTTP_GET_VARS;
if (isset($sessionid) && isset($HTTP_GET_VARS['sessionid']) && ($HTTP_COOKIE_VARS['sessionid'] != $HTTP_GET_VARS['sessionid'])) {
SetCookie('sessionid', $HTTP_GET_VARS['sessionid'], 0, '/', '');
$HTTP_COOKIE_VARS['sessionid'] = $HTTP_GET_VARS['sessionid'];
$sessionid = $HTTP_GET_VARS['sessionid'];
}
?>
Once this code has been run, a global variable
'sessionid' will be available
to the script. It will contain the value of the sessionid from the users
cookie, or the value sent along with a GET request.Step 2: Using Variables For All Cross-Domain Hrefs
Create a global configuration file that contains the base hrefs of the domains
you are switching between. For example, if we have domain1.com and domain2.com, set
the following:
<?php
$domains['domain1'] = "http://www.domain1.com/-$sessionid-";
$domains['domain2'] = "http://www.domain2.com/-$sessionid-";
?>
Now, if you do the following in your code...
<?php
echo "Click <a href=\"", $domains['domain2'], "/contact/?email=yes\">here</a> to contact us.";
?>
...you will produce the following output...
Click <a href="http://www.domain2.com/-66543afe6543asdf6asd-/contact/?email=yes\">here</a> to contact us.
...where the sessionid has been inserted into the URL.
At this point, you are probably thinking "this will try to open a subdirectory on
the webserver called dash, sessionid, dash?!?!?". However, the next step will provide the necessary
magic to make it all work - mod_rewrite!
[ Next Page ]
| Comments: | ||
| Cross Domain | Lavanya | 05/23/08 03:23 |
| RE: (yet(yet)) another possible | Guus derks | 12/13/07 04:48 |
| RE: Cross Domain | samantha | 02/19/05 07:03 |
| RE: EASIER Cross Domain | Michael | 10/28/03 19:56 |
| Setting cookies on a Linux Webserver | Siva | 10/17/02 02:07 |
| RE: expiring cookies. | Keri Henare | 07/25/02 04:01 |
| RE: (yet(yet)) another possible | Danny Tuppeny | 09/12/01 09:28 |
| RE: Great, why use rewrite at all? | Danny Tuppeny | 09/12/01 09:24 |
| RE: Why not use redirection? | Danny Tuppeny | 09/12/01 09:22 |
| expiring cookies. | nagaraj | 09/12/01 05:50 |
| RE: Privacy Concerns of John Q. Public | Jesse | 08/03/01 14:49 |
| (yet(yet)) another possible | Hugh | 02/24/01 16:37 |
| RE: Not a session | Phil Greenway | 02/15/01 16:33 |
| RE: Another method | David Davis | 02/02/01 14:16 |
| Yet another way | sander | 12/16/00 15:15 |
| RE: I think I would have... | Chris Kings-Lynne | 12/04/00 21:08 |
| RE: Another method | Matthew Kendall | 12/04/00 02:26 |
| Another method | Andrew Dickinson | 12/03/00 15:09 |
| Privacy Concerns of John Q. Public | Jim Hawley | 12/02/00 11:07 |
| Great, why use rewrite at all? | Brian Tanner | 12/01/00 20:51 |
| Why not use redirection? | Johannes Erdfelt | 12/01/00 14:17 |
| RE: Cookies | Hreinn Beck | 12/01/00 04:51 |
| I think I would have... | Paul K Egell-Johnsen | 11/30/00 13:13 |
| RE: Cross Domain | marcoBR | 11/29/00 20:14 |
| RE: Cross Domain | Robert | 11/29/00 19:25 |
| deleting cookies | Donncha O Caoimh | 11/29/00 08:03 |
| Cross Domain | Micheal O Shea | 11/29/00 07:23 |
|
If you are looking for help, please post on the appropriate forum here. Your questions will be answered much more quickly. | ||


