首页 > 解决方案 > 如何在外部使用 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 等,尽管我还没有测试过。

标签: phpwordpress

解决方案


推荐阅读