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 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题