http//www.phprecord.com_php tutorial for implementing cross-domain cookie transfer

Source: Internet
Author: User
Author: Christopher Kings-lynne translation: Limodou 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. 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 prefer a get variable than a cookie. 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 to add the following code to the preset script (or to a function that precedes all scripts). Once this code is run, a global SessionID variable will be available for scripting. It will hold the SessionID value in the user's cookie, or the SessionID value sent through the GET request. Step two: Use variables for all cross-domain references to create a global profile 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: Now, if you do this in your code: You will produce the following output: Click here for contact us.   Here SessionID has been inserted into the URL. In this place, you might think, "this might open a subdirectory called horizontal, SessionID, horizontal lines on the Web server?!?!?". However, the following steps will provide a required trick so that it can be used! Step three: Configure Apache now, the rest of the steps are to configure Apache to rewrite this url:http://www.domain2.com/-66543afe6543asdf6asd-/contact/into this:/HTTP WWW.DOMAIN2.COM/CONTACT/?SESSIONID=66543AFE6543ASDF6ASD and this url:http://www.domain2.com/-66543afe6543asdf6asd-/ Contact/?email=yes became like this: HTTP://WWW.DOMAIN2.COM/CONTACT/?EMAIL=YES&SESSIONID=66543AFE6543ASDF6ASD to achieve 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 overridden rules implement the requirements of the above two URL overrides. Conclusion the cross-domain cookie can be implemented in a simple way by using the variable combination with the rewrite function of Apache. To maintain such a system, no matter when the link cross-domain name, in the use of domain variables, nothing to do!   The link within the domain name does not need to be modified because the cookie will work properly. If you are interested in looking at the actual operating system in the production network, please visit http://www.familyhealth.com.au/.   Move your mouse over some cross-domain links and see how they are rewritten when you click. Perhaps the only problem with this technology is the inability to delete cookies from all domain names in the user's browser. Transferred from: phpbuilder.com

http://www.bkjia.com/PHPjc/531774.html www.bkjia.com true http://www.bkjia.com/PHPjc/531774.html techarticle Author: Christopher Kings-lynne translation: Limodou cookies are a great invention that allows web developers to retain their users ' login status. However, when your site or network has ...

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