如何从服务器上的php脚本获取php脚本的echo输出?

时间:2021-01-04 01:23:44

I am working on a backend for my school's website and I have run into a problem. I am powering a blog on the homepage and for teacher websites and have setup an SSO system between the two. I am linking into it for a unified admin panel that I am making to manage them and a dynamic calendar via a php script that is placed inside of the homepage's blog directory. It doesn't work if it is not in the blog's directory My problem is that it echos a JSON array of the current logged in user and I am having trouble getting the json array from the admin panel that I am developing. Here is the code of the script in the blog's directory:

我正在为学校的网站做后台工作,我遇到了一个问题。我在主页和教师网站上建立了一个博客,并在两者之间建立了一个SSO系统。我正在将它链接到一个统一的管理面板中,用于管理它们,并通过放置在主页博客目录中的php脚本创建一个动态日历。如果不在blog的目录中,它就不能工作,我的问题是它会对当前登录用户的JSON数组进行响应,而且我在从我正在开发的管理面板中获取JSON数组时遇到了麻烦。以下是博客目录中的脚本代码:

<?php
error_reporting(E_ALL);
ini_set('display_errors', 'on');
include 'wp-blog-header.php';

global $current_user;
get_currentuserinfo();

if (is_user_logged_in()) {
    $userInfo = ((array) $current_user);
    $loggedIn = true;
} else {
    $userInfo = null;
    $loggedIn = false;
}

echo json_encode(array(
    'loggedIn' => $loggedIn,
    'userInfo' => $userInfo
));
?>

Here is the code of the current script in the admin panel:

以下是管理面板中当前脚本的代码:

<?php
error_reporting( E_ALL );
ini_set('display_errors', 'on');
$response = file_get_contents(dirname(dirname(dirname(__FILE__))) . '/homepage-blog/controlPanelUserCommunicate.php');
var_dump($response);
?>

Here is the output of current script in the admin panel:

下面是管理面板中当前脚本的输出:

string(374) " $loggedIn, 'userInfo' => $userInfo )); ?>"

1 个解决方案

#1


1  

you accessing the file directly, so you gets contents, its not being run though the web server to process the php

您可以直接访问文件,这样就可以获得内容,而不是通过web服务器运行来处理php

you probably want

你可能想要的

$response = file_get_contents('http://SITE/controlPanelUserCommunicate.php');

#1


1  

you accessing the file directly, so you gets contents, its not being run though the web server to process the php

您可以直接访问文件,这样就可以获得内容,而不是通过web服务器运行来处理php

you probably want

你可能想要的

$response = file_get_contents('http://SITE/controlPanelUserCommunicate.php');