In php I set a cookie, now I need it on another page of the same site via javascript. I entered the following code in the address bar and got an empty line.

javascript:alert(document.cookie); 

On the site Google, for example, everything works, displays. Checked through Chrome - everything is fine, exists, matters and is enabled for scripts (HttpOnly is disabled). I created a new php file and requested a cookie through the $ _COOKIE array, I got it, everything is fine, but I still can't get through JS!

    1 answer 1

    1. Do you have the same domain from which cookies are added, and from which they are read by scripts?
    2. The path of the cookie. You can create a cookie that is available only for a specific directory, for example, and it will not be available at a different address.
    • 1. Already wrote. Yes, from the same. 2. Cookies were created via setcookie using only names and values. Now I turned to the same directory where the script that created one of the cookies is located. In it, it is available for reading. Added time parameter and path in setcookie in php file, now everything works! Thank! - SemperPeritus pm