On Wed, 20 Feb 2002, Ben Sinclair wrote:

> I want to retain some data across my sites, which have different domain names.
> I can't use cookies because they rely on the domain name, and I'd rather not

One way I handle this ... it's a work-around, so it's not all that pretty:

In the doc root on all the domains, I keep a script which just prints out
the cookie names & values for any cookies accessible by the domain ... as
JavaScript variables.  Then that script can be used as the src in a
<script> on any of your other domains.  BINGO ... you've got cookies!

Want milk?

On domain_A, have this script (let's call it A_cookies.php):

while( list( $key, $val ) = each( $HTTP_COOKIE_VARS ) ){
        print( "var $key = \"$val\";\n" );
}

On domain_B, in an HTML document, use some JavaScript:

<script src="http://domain_A/A_cookies.php";></script>

The pitfalls:
- not useful with users whom have JavaScript or cookies disabled
- now you have to do all cookie data handling on the client side
- this is a "third-party activity"[1] which more secure-minded people and
  browsers will disallow.  (IE6, as a P3P-enabled user agent, is a prime
  example.)

I only do this for data which makes the user experience better between two
sites.  It's one of those "bells and whistles" kind of deals.  When it
doesn't work as desired, the sites still function properly.

If I were to try this to track data on a particular user between sites,
I'd store only a session ID in a cookie (a la PHP sessions), use the above
method to get the session ID data into a javascript variable and source it
across sites, then use custom session handlers to put session data into a
single database, with the data associated to the session ID.  The same
pitfalls apply ... so you'd lose track of some visitors when they switch
sites.  I don't consider this a big deal, because this is just how the
Internet is evolving.

        g.luck
        ~Chris

[1] Having a file from domain_B referenced from within a document on
domain_A renders the file from domain_B a third-party document.  There are
inititives to control third-party cookie reading/writing, like banner ads,
and they affect this method of cookie reading too.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to