Cookies are a great invention that allows web developers to retain their users ' login status. However, when your site or network
When there is more than one domain name, there will be a problem.
In the cookie specification, a cookie can only be used for a domain name and cannot be issued to another domain name. Therefore, if you set a cookie in the browser for a domain name, this cookie will not work for the other domain names. If you want your users to log in from one of your sites and also log on to other domains, this is a big challenge.
My solution will use the following general framework:
A preset script will be used to accept the SessionID number passed through a Get or cookie method. It will be preferred than cookie to get
Variable. So whenever we need to refer to a cross-domain name, we send SessionID as a URL parameter. Modify the Apache configuration to implement cookies that rewrite all cross-domain names. The reason for doing so will be clear in a moment. Use a variable at any time when a cross-domain name reference occurs.
First step: Create a preset script
Add the following code to the preset script (or to a function that precedes all scripts).
/* Support for cross-domain cookies ... */
If the get variable is already set, and it is different from the cookie variable
Use the Get variable (update 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 is run, a global ' sessionid ' variable will be available for scripting. It will save the user's cookie
The SessionID value, or the SessionID value that is sent through the GET request.
Step two: Use variables for all cross-domain references
Create a global configuration file that holds the basic reference form for the domain name that can be toggled. For example, if we have
Domain1.com and Domain2.com, the following settings are set:
$domains [' domain1 '] = "http://www.domain1.com/-$sessionid-";
$domains [' domain2 '] = "http://www.domain2.com/-$sessionid-";
?>
Now, if you do this in your code:
echo "Click <a href=" ", $domains [' domain2 '],"/contact/?email=yes ">here</a> to contact us.";
http://www.bkjia.com/PHPjc/445266.html www.bkjia.com true http://www.bkjia.com/PHPjc/445266.html techarticle cookies are a great invention that allows web developers to retain their users ' login status. However, when your site or network has more than one domain name, there will be a problem. ...