how to retrieve a value of a cookie php

2019-08-08 02:56发布

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.

标签: php wordpress
3条回答
叛逆
2楼-- · 2019-08-08 03:32

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 ..

查看更多
不美不萌又怎样
3楼-- · 2019-08-08 03:34

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.

查看更多
乱世女痞
4楼-- · 2019-08-08 03:42

Look in $_COOKIE.

However, keep in mind, that the path may be set different to where you want to read it.

查看更多
登录 后发表回答