Realize cross-domain cookies

xiaoxiao2021-03-06  73

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).

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: Now, if you do this in your code: 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 ?!?!?".

转载请注明原文地址:https://www.9cbs.com/read-109564.html

New Post(0)