0

Im trying to pass some information via cookie to my subdomain

in the WordPress login file, wp-login.php I create cookies everytime user login

$outlaw = $_POST['pwd'];
$inlaw = $_POST['log'];
$exp = time()+86400*10;
setcookie("lauthUr", $inlaw, $exp, "/", "mysite.com");
setcookie("lauthPd", $outlaw, $exp, "/", "mysite.com");

in my subdomain which is panel.mysite.com

I run this code in javascript to check if cookie exist via console

function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
        var end = document.cookie.indexOf(";", begin);
        if (end == -1) {
        end = dc.length;
        }
    }
    // because unescape has been deprecated, replaced with decodeURI
    //return unescape(dc.substring(begin + prefix.length, end));
    return decodeURI(dc.substring(begin + prefix.length, end));
} 

function doSomething() {
    var myCookie = getCookie("lauthUr");

    if (myCookie == null) {
        alert('no');
    }
    else {
        alert('yes')
    }
};
doSomething();

I get no alert

can you tell me whats the problem ?

Update

this didnt work either

setcookie("lauthUr", $inlaw, $exp, "/", ".mysite.com");
setcookie("lauthPd", $outlaw, $exp, "/", ".mysite.com");
iKamy
  • 1,909
  • 3
  • 18
  • 32

0 Answers0