http://www.openphp.cn/index.php?module=article&id=70 cookie is a great invention that allows web developers to keep their users' login status. However, there will be problems when your site or network has more than one domain name. In the cookie specification, a cookie can only be used for one domain name and cannot be sent to other domain names. Therefore, if a cookie is set to a domain name in the browser, this cookie is invalid for other domain names. If you want your user to log in from one of your sites, you can also log in on other domain names, which is really a big problem. My solution will use the following general frame: a preset script will be used to accept the sessionID number passed through GET or COOKIE mode. It will select Get variables than cookies. So, whenever you need to reference the domain name of the crossed, we use the sessionID as a URL parameter. Modify the Apache configuration to rewrite all Cookies of all cross-domain names. The reason for this will be clear for a while. Use variables when a cross-domain name appears at any time. The first step: Creating a preset script will add the following code to the preset script (or in a function before all scripts). php / * supports cross-domain name cookie ... If the get variable has been set, it is different from the cookie 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 runs, a global 'sessionId' variable will be available for scripts. It will save the sessionID value in the cookie of the user, or the sessionID value sent by the GET request. Step 2: Creating a global profile for all cross-domain names, creating a global configuration file for storing the basic reference form of domain names that can be switched. For example, if we have Domain1.com and Domain2.com, you set the following: Php $ domains ['Domain1'] = "http://www.domain1.com/- $ domains ['Domain2 '] = "http://www.domain2.com/- $$ ionID-";> Now, if you do this in your code: PHP Echo "Click here to contact us. "> You will produce the following output: Click here to contact us. The sessionID here has been inserted into the URL. In this place, you may think "this may open the subdirector of the horizontal line, sessionid, horizontal line on the web server ?!?!?".