Cross-domain Cookie transfer to http // www.phprecord.com _ PHP Tutorial

Source: Internet
Author: User
Implement cross-domain Cookie conversion to httpwww.phprecord.com. LimodouCookie is a great invention that allows web developers to retain the logon status of their users. However, when your site or network has Author: Christopher Kings-Lynne translation: limodou Cookie is a great invention that allows web developers to retain the login status of their users. However, problems may occur when your site or network has more than one domain name. In terms of 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 for a domain name in the browser, the cookie will be invalid for other domain names. If you want your users to log on from one of your sites, you can also log on to other domain names, which is really a big challenge. My solution will use the following general framework: a preset script will be used to accept the sessionid passed through the GET or COOKIE method. It gives priority to GET variables than cookies. Therefore, whenever cross-domain names need to be referenced, sessionid is sent as a URL parameter. Modify Apache configuration to rewrite all cross-domain cookies. The reason for doing so will be clear later. Use variables when a cross domain name is referenced at any time. Step 1: Create a preset script to add the following code to the preset script (or appear in the function before all scripts ). Once the code is run, a global sessionid variable can be used in the script. It stores the sessionid value in your cookie, or the sessionid value sent through the GET request. Step 2: create a global configuration file for all cross domain name references using variables to store the basic reference form of domain names that can be switched. For example, if we have domain1.com and domain2.com, the settings are as follows: Now, if you do the following in the code: You will generate the following output: Click here to contact us. here sessionid has been inserted into the URL. In this place, you may think, "This may open the sub-directory named horizontal line, sessionid, and horizontal line on the web server ?!?!? ". However, the following steps provide a required trick for it to use! Step 3: Configure Apache now, the remaining step is to configure apache to override this URL: the http://www.domain2.com/-66543afe6543asdf6asd-/contact/ becomes like this: http://www.domain2.com/contact? Sessionid = 66543afe6543asdf6asd and this url: http://www.domain2.com/-66543afe6543asdf6asd-/contact? Email = yes becomes like this: http://www.domain2.com/contact? Email = yes & sessionid = 66543afe6543asdf6asd in order to implement it, simply configure two virtual servers as domain1 and domain2, as follows: DocumentRoot/usr/local/www/domain1 ServerName www.domain1.com RewriteEngine on RewriteRule ^ /-(.*)-(.*?. *) $2 & sessionid = $1 [L, R, QSA] RewriteRule ^/-(. *)-(. *) $2? Sessionid = $1 [L, R, QSA] DocumentRoot/usr/local/www/domain2 ServerName www.domain2.com RewriteEngine on RewriteRule ^ /-(.*)-(.*?. *) $2 & sessionid = $1 [L, R, QSA] RewriteRule ^/-(. *)-(. *) $2? Sessionid = $1 [L, R, QSA] These rewrite rules meet the requirements for rewriting the above two URLs. Conclusion using the combination of variables and the rewrite function of apache, cross-domain cookie can be implemented in a simple way. If you want to maintain such a system, no matter when the cross-domain name is linked, you don't need to do anything except the domain name variable! The link in the domain name does not need to be modified because the cookie will work normally. If you are interested in viewing the systems in the production network, visit http://www.familyhealth.com.au /. Move your mouse over some cross-domain links and see how they are overwritten after you click. Maybe the only problem with using this technology is that the cookie under all domain names in the user's browser cannot be deleted.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.