如何检索cookie php的值 [英] how to retrieve a value of a cookie php

查看:30
本文介绍了如何检索cookie php的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我安装了 wordpress,当用户登录时,它会在临时文件中保存一个名为 wordpress 的 cookie.

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

我想在另一个页面(在 wordpress 之外)中使用 php 检索 cookie 的值.在 php 中检索持久性 cookie 的方法是什么.

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.

推荐答案

我注意到本地 worpress 安装中有三个键值对.如果您可以将 php 文件放在同一个域下,那么您就可以获取 cookie,因为它看起来会适当地将 cookie 设置为/".因此,例如键wp-settings-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

cookie_test.php

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

}

它必须在同一个域下.在本地,我只是将它放在 worpress 文件夹中的任何位置,当您浏览到它时它就会工作.

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.

这篇关于如何检索cookie php的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆