php - 如何在外部使用 php 验证 wordpress 用户
问题描述
我正在使用 GD php 将图像注入 HTML 标记,并且我想确保 Wordpress 用户可以访问该图像。
我的 Wordpress 页面上有一个 img 标签,它从数据库中提取的数据生成图像。
<img src=\""+imagepath+"image.php?file="+fn+"&layout="+layout+"&w="+window.innerWidth+"&h="+window.innerHeight+"\" />
image.php 的内容:
<?php
include_once('../../../wp-load.php');
$current_user = wp_get_current_user();
$userID=$current_user->ID;
error_log("\n".$userID."-:-\n");
$path=realpath('.').'/';
$width=$_GET['w'];
$height=$_GET['h'];
$im = ImageCreate($width,$height);
$white = ImageColorAllocate($im,0xFF,0xFF,0xFF);
$black = ImageColorAllocate($im,0x00,0x00,0x00);
ImageFilledRectangle($im,50,50,$width-100,$height-100,$black);
imagefttext($im,12,0,60,60,$white,$path."ARIAL.TTF",$userID);
imagefttext($im,12,0,60,160,$white,$path."ARIAL.TTF",$_GET['file']);
header('Content-Type: image/png');
ImagePNG($im);
?>
我猜“wp-load.php”定义了与“Content-Type: image/png”冲突的标题。
有没有一种方法可以验证用户,以便我可以看到他是否应该有权访问图像?我还需要访问数据库,但我很确定我可以包含 DB_NAME 的 wp-config.php 等,尽管我还没有测试过。
解决方案
推荐阅读
- c++ - != 在 C++20 中从 == 自动生成?
- elasticsearch - Elasticsearch 多索引查询
- twig - Drupal 8,Twig - 如何从自定义视图模板输出字段,并检查分类术语
- dask - 如何将分区中的最后一个条目与下一个分区中的第一个相结合?
- mongodb - Sonata/Symfony 使用 MongoDB 过滤 Null
- scala - 在 scala 中,如何访问元组中的特定索引?
- amazon-web-services - Nat Gateway 数据传输成本分析
- r - 如何在 tidyverse 中使用 to_factor 的参数
- javascript - 绘图时画布签名/点的问题
- java - Libsodium 和 Javax 加密有什么区别