doutang7415 2013-10-07 23:44
浏览 60
已采纳

将Wordpress会话转换为用户ID

I am working on a WordPress plugin and I have a problem where I get the WordPress logged-in users id & session and i need to create a comment on this user's behalf from my server.

[Update] What I mean by "my server" is from my own Java server. My comment system creates the comments on the Java server and the Java server needs also to create the same comment on the wordpress PHP server. In order to create the comment on the user account i am sending the session to the Java server so it will as the wordpress to convert the session to the user, so it will be secure. [/update]

The problem is that in order to make this operation secure i need to check with WordPress that the session i got is valid and matches the user id.

I couldn't find any API that convert the session into the user id in order to check that it matches.

anyway to do that with WordPress API?

  • 写回答

1条回答 默认 最新

  • dtftao7249656 2013-10-10 10:24
    关注

    There are a number of ways you can get the user id from the auth cookie, depending on the path you want to take this are the functions you should check:

    get_current_user_id ->Returns the ID of the current user.
    wp_get_current_user ->Retrieve the current user object (WP_User).
    Wrapper of get_currentuserinfo() using the global variable $current_user. You can check the code of this function here to have an ideea how you can build your script.


    wp_validate_auth_cookie -Validates authentication cookie. It returns the user id.
    I'm thinking you'll have to use the last one like it is used in get_currentuserinfo:

    $user = wp_validate_auth_cookie( $_COOKIE[LOGGED_IN_COOKIE], 'logged_in' )
    if ($user != 0) { //then we have a valid user...}
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥15 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)