douti0687 2017-09-29 12:32
浏览 55

如何在同一域上的独立Angular APP中读取WordPress身份验证cookie?

What would be the best way to display a login info on an HTML page which sits at the same website which is running on WordPress?

Since we're talking about an html page here, I suppose that document.write is the one good way to eventually put that login info on the page; But, how do you find out about the login Status? That's where the real question lies.

Scenario:

You are on an empty index.html file, which, let's say, sits as www.example.com/my-special-app/index.html

And you got a WordPress website running at www.example.com,

And depending on whether the user currently logged-in to the WordPress or not, you want to display:

Welcome Anonymous, [login]

OR

Welcome Joe, [log-out]

on the page, as soon as the user lands on that index.html page.

The page's being an html page makes this difficult to get at, at least in my mind.

If this was a php page ( such as index.php ), I would just use include the wordpress blog header with the load theme option set to false and then use wordpress API's to figure out the login status.

But I've got to deal with an index.html situation, here. The only thing I can think of is to tap into the wordpress authentication cookies, and somehow pull this off using pure JS. But there are cookie hashes, and wordpress authentication cookie is not a guessable one. So there is some complexity there.

As far as I know, the WP cookie-hash uses an md5 like this:

$cookie_hash = md5("http://www.example.com");

Ad the wordpress authentication cookie name then happens to be

$wordpress_logged_in_cookie_name = wordpress_logged_in_'.$cookie_hash;

But is this reliable, is it so, all the time?

Eventually, I will be needing this in an angular Application. ( AngularJS but Angular ) and when the Angular app initializes, I'd like it to move on with the session info at hand and obviously do not require another login for the current user!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 求差集那个函数有问题,有无佬可以解决
    • ¥15 【提问】基于Invest的水源涵养
    • ¥20 微信网友居然可以通过vx号找到我绑的手机号
    • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
    • ¥15 解riccati方程组
    • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
    • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
    • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
    • ¥50 树莓派安卓APK系统签名
    • ¥65 汇编语言除法溢出问题