What code do I use to check for Cookie?

Discussion in 'Programming' started by MindReality, Jul 4, 2013.

  1. #1
    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?

    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))​
     
    MindReality, Jul 4, 2013 IP
  2. ByteCoder

    ByteCoder Active Member

    Messages:
    239
    Likes Received:
    2
    Best Answers:
    2
    Trophy Points:
    65
    #2
    Hey mate,
    for security needs that would never be approved from the browser running JS/PHP.
    if that was possible, what would prevent you from taking the users' paypal cookies aswell? :)
    cookies are accessible only for the domain that created them in first place.

    What you can still do is, if you run several sites and you've got the user's trust etc - create an activex plugin or any kind of browser plugin that can read all of the user's cookies and see if any of them is your's and if so - change the user automatically to a logged on status or whatever you wish.
     
    ByteCoder, Jul 5, 2013 IP
  3. archert22

    archert22 Greenhorn

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #3
    ^ Agreed with above post.

    JavaScript prevents you from reading cookies that do not belong to the domain you're currently in. I think another alternative to the activex plugin is that you may be able to read and write storage using HTML5 local storage now... I'm not sure if they patched that in the newest spec but would be good to investigate further.
     
    archert22, Jul 9, 2013 IP