how to retrieve a value of a cookie php

I have wordpress installed and when a user logs in, it saves a cookie in the temporary files with the name of wordpress.

I want to retrieve the value of the cookie using php in another page (out of wordpress). What would be a method to retrieve a persistent cookie in php.

Related posts

Leave a Reply

3 comments

  1. I notice three key value pairs on my local worpress installation. If you can place the php file under the same domain, then you can obtain the cookies as it appears worpress appropriately sets the cookie to “/”. So for instance the key “wp-settings-1”.

    cookie_test.php

    if(isset($_COOKIE["wp-settings-1"]))
    {
        echo "Cookie: {$_COOKIE['wp-settings-1']}";
    }
    else
    {
        echo "<h1>No Cookie Detected from wordpress!</h1>";
    
    }
    

    It has to be under the same domain. Locally I just drop this anywhere in the worpress folder and it will work when you browse to it.

  2. You keep saying that its under localhost. But the point is, the cookie data wont be available between subdirectories of localhost. like the cookie set at http://localhost/wordpress wont be available at http://localhost/drupal .. you can only access the cookies of http://localhost/wordpress in that directory or subdirectories of it e.g. http://localhost/wordpress/test-page ..