简体   繁体   中英

How can I get the echo output of a php script from a php script on my server?

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:

<?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 )); ?>"

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

you probably want

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM