gpt4 book ai didi

php - 在没有 SSL/OAuth 的情况下向 Wordpress 提交评论

转载 作者:太空宇宙 更新时间:2023-11-03 14:56:14 24 4
gpt4 key购买 nike

我想让 android/iPhone 用户匿名(无需注册博客)向自托管的 Wordpress 博客提交评论。

是否有一种简单、安全的方法来做到这一点?

到目前为止我研究了什么:

JSON API 插件 -> 运行良好,但不安全。

WP-API -> 没有实现提交评论方法 + 没有安全性。

最佳答案

好吧,你可以只使用随机数来避免 XSS 攻击,除此之外你显然需要你的用户登录。这是一个简单的方法来做到这一点。

https://wordpress.org/support/topic/plugin-json-api-how-to-add-a-comment-or-post

编辑:如果您只需要能够使用他们的姓名和电子邮件地址发表评论。如下使用它,但请确保您从 api 设置中启用“响应 Controller ”

http://yourwebsite.com/api/?json=submit_comment&post_id=170&name=Omer&email=commenter@gmail.com&content=comment

第二次编辑:为了保护评论,您可以使用随机数,如果它不是插件的内置功能,您必须在 submit_comment Controller 中添加此功能。但是从你的 android 应用程序生成随机数会有点困难。一个简单的解决方案是将现有代码包装在一个条件中。类似于 base64 编码的时间 token 。

if(isset($_GET['token'])){
$token = base64_decode($_GET['token']);
$current_time = time();
$difference = round(abs($current_time - $token) / 60,2);//difference in minutes
if($difference < 5){
// Run the code thats already in submit_comment controller.
}
}

然后在 REST api 中,您可以发送类似

的内容
http://yourwebsite.com/api/?json=submit_comment&post_id=170&name=Omer&email=commenter@gmail.com&content=comment&token=BASE64_ENCODED_TIMESTAMP

关于php - 在没有 SSL/OAuth 的情况下向 Wordpress 提交评论,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28979381/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com