What code do I use to check for Cookie?

by 13 replies
16
Hi,

The code I am using only checks cookie name from the URL my browser is on.

How can I check for a cookie name no matter what URL it came from?

For example, if the cookie "popover" comes from "mindreality.com", how can I check for it even if it comes from "ubermanpower.com" or any other URL without being restricted to the URL that my browser is on?
#programming #check #code #cookie
  • You cant with a server side script. That is from website A you can only read cookies that are from website A not from any other website:

    Same origin policy - Wikipedia, the free encyclopedia
    • [ 1 ] Thanks
    • [1] reply
    • What I mean is, if the browser (Firefox for e.g.) is already cookied with "popover" from "Ubermanpower.com" but right now it is viewing "MindReality.com", I want my code on "MindReality.com" to be able to check for the cookie "popover" even though it is from "Ubermanpower.com. Keep in mind that the browser is already cookied.

      How do I do that?

      My code is:

      Code:
      function getcookie(cookiename) {
       var cookiestring=""+document.cookie;
       var index1=cookiestring.indexOf(cookiename);
       if (index1==-1 || cookiename=="") return ""; 
       var index2=cookiestring.indexOf(';',index1);
       if (index2==-1) index2=cookiestring.length; 
       return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
      
      function cookiecheck(){
      var currentvalue;
      var uservalue =1;
      var popoverdelay = 0;
      if(getcookie('popover') > 0){
      currentvalue = getcookie('popover');
      if(currentvalue == (uservalue+1))
  • Cookies are presented only for the site the browser is on, and to there. So if a user vists mysite.com, you can't get the cookies for google.com on mysite.com. Javascript is ALSO run from the site and subject to those constraints.

    Steve
    • [ 1 ] Thanks
  • You can check and set cookies using php server side scripting i dont think without server side scripting you will be able to do it
    • [1] reply
    • What is an example of how this work? The domains are on my server.
      • [1] reply
  • You can set cookie using any service side scripting you can use asp.net or php for setting up the cookies and then for the reading of the cookies
    • [1] reply
    • Can you show me an example of this?

      How can I set the cookie "popover" from one domain, and check for it on another?
      • [1] reply

Next Topics on Trending Feed