1

我不知道这是否可能

我在两个网站上工作,我想通过 URL 将数组从一个站点传递到另一个站点

例如

$myreceivearray = http://mydomain/myscript.php

这个 myscript.php 应该返回一个数组。

再次在问题中添加一些部分

根据我试过的答案,我的 myscript.php 代码是

<?php
if (session_id() == "") session_start(); // Initialize Session data
ob_start(); // Turn on output buffering
?>
<?php include_once "ewcfg10.php" ?>
<?php include_once "adodb5/adodb.inc.php" ?>
<?php include_once "phpfn10.php" ?>
<?php include_once "ACCOUNTinfo.php" ?>
<?php include_once "userfn10.php" ?>
<?php

//
// Page class
//

$custompage = NULL; // Initialize page object first

class ccustompage {

    // Page ID
    var $PageID = 'custompage';

    // Project ID
    var $ProjectID = "{D5B1B389-2DCD-4664-BAD5-27C1596B8577}";

    // Page object name
    var $PageObjName = 'custompage';

    // Page name
    function PageName() {
        return ew_CurrentPage();
    }

    // Page URL
    function PageUrl() {
        $PageUrl = ew_CurrentPage() . "?";
        return $PageUrl;
    }

    // Message
    function getMessage() {
        return @$_SESSION[EW_SESSION_MESSAGE];
    }

    function setMessage($v) {
        ew_AddMessage($_SESSION[EW_SESSION_MESSAGE], $v);
    }

    function getFailureMessage() {
        return @$_SESSION[EW_SESSION_FAILURE_MESSAGE];
    }

    function setFailureMessage($v) {
        ew_AddMessage($_SESSION[EW_SESSION_FAILURE_MESSAGE], $v);
    }

    function getSuccessMessage() {
        return @$_SESSION[EW_SESSION_SUCCESS_MESSAGE];
    }

    function setSuccessMessage($v) {
        ew_AddMessage($_SESSION[EW_SESSION_SUCCESS_MESSAGE], $v);
    }

    function getWarningMessage() {
        return @$_SESSION[EW_SESSION_WARNING_MESSAGE];
    }

    function setWarningMessage($v) {
        ew_AddMessage($_SESSION[EW_SESSION_WARNING_MESSAGE], $v);
    }

    // Show message
    function ShowMessage() {
        $hidden = FALSE;
        $html = "";

        // Message
        $sMessage = $this->getMessage();
        $this->Message_Showing($sMessage, "");
        if ($sMessage <> "") { // Message in Session, display
            if (!$hidden)
                $sMessage = "<button type=\"button\" class=\"close\" data-dismiss=\"alert\">&times;</button>" . $sMessage;
            $html .= "<div class=\"alert alert-success ewSuccess\">" . $sMessage . "</div>";
            $_SESSION[EW_SESSION_MESSAGE] = ""; // Clear message in Session
        }

        // Warning message
        $sWarningMessage = $this->getWarningMessage();
        $this->Message_Showing($sWarningMessage, "warning");
        if ($sWarningMessage <> "") { // Message in Session, display
            if (!$hidden)
                $sWarningMessage = "<button type=\"button\" class=\"close\" data-dismiss=\"alert\">&times;</button>" . $sWarningMessage;
            $html .= "<div class=\"alert alert-warning ewWarning\">" . $sWarningMessage . "</div>";
            $_SESSION[EW_SESSION_WARNING_MESSAGE] = ""; // Clear message in Session
        }

        // Success message
        $sSuccessMessage = $this->getSuccessMessage();
        $this->Message_Showing($sSuccessMessage, "success");
        if ($sSuccessMessage <> "") { // Message in Session, display
            if (!$hidden)
                $sSuccessMessage = "<button type=\"button\" class=\"close\" data-dismiss=\"alert\">&times;</button>" . $sSuccessMessage;
            $html .= "<div class=\"alert alert-success ewSuccess\">" . $sSuccessMessage . "</div>";
            $_SESSION[EW_SESSION_SUCCESS_MESSAGE] = ""; // Clear message in Session
        }

        // Failure message
        $sErrorMessage = $this->getFailureMessage();
        $this->Message_Showing($sErrorMessage, "failure");
        if ($sErrorMessage <> "") { // Message in Session, display
            if (!$hidden)
                $sErrorMessage = "<button type=\"button\" class=\"close\" data-dismiss=\"alert\">&times;</button>" . $sErrorMessage;
            $html .= "<div class=\"alert alert-error ewError\">" . $sErrorMessage . "</div>";
            $_SESSION[EW_SESSION_FAILURE_MESSAGE] = ""; // Clear message in Session
        }
        echo "<table class=\"ewStdTable\"><tr><td><div class=\"ewMessageDialog\"" . (($hidden) ? " style=\"display: none;\"" : "") . ">" . $html . "</div></td></tr></table>";
    }

    //
    // Page class constructor
    //
    function __construct() {
        global $conn, $Language, $UserAgent;

        // User agent
        $UserAgent = ew_UserAgent();
        $GLOBALS["Page"] = &$this;

        // Language object
        if (!isset($Language)) $Language = new cLanguage();

        // User table object (ACCOUNT)
        if (!isset($GLOBALS["ACCOUNT"])) $GLOBALS["ACCOUNT"] = new cACCOUNT;

        // Page ID
        if (!defined("EW_PAGE_ID"))
            define("EW_PAGE_ID", 'custompage', TRUE);

        // Start timer
        if (!isset($GLOBALS["gTimer"])) $GLOBALS["gTimer"] = new cTimer();

        // Open connection
        if (!isset($conn)) $conn = ew_Connect();
    }

    // 
    //  Page_Init
    //
    function Page_Init() {
        global $gsExport, $gsExportFile, $UserProfile, $Language, $Security, $objForm;

        // Security
        $Security = new cAdvancedSecurity();
        if (!$Security->IsLoggedIn()) $Security->AutoLogin();

        // Uncomment codes below for security
        //if (!$Security->IsLoggedIn())
        //  $this->Page_Terminate("login.php");

        if (@$_GET["export"] <> "")
            $gsExport = $_GET["export"]; // Get export parameter, used in header
        $this->CurrentAction = (@$_GET["a"] <> "") ? $_GET["a"] : @$_POST["a_list"]; // Set up curent action
        global $gbOldSkipHeaderFooter, $gbSkipHeaderFooter;
        $gbOldSkipHeaderFooter = $gbSkipHeaderFooter;
        $gbSkipHeaderFooter = TRUE;

        // Global Page Loading event (in userfn*.php)
        Page_Loading();

        // Page Load event
        $this->Page_Load();
    }

    //
    // Page_Terminate
    //
    function Page_Terminate($url = "") {
        global $conn;
        global $gbOldSkipHeaderFooter, $gbSkipHeaderFooter;
        $gbSkipHeaderFooter = $gbOldSkipHeaderFooter;

        // Page Unload event
        $this->Page_Unload();

        // Global Page Unloaded event (in userfn*.php)
        Page_Unloaded();
        $this->Page_Redirecting($url);

         // Close connection
        $conn->Close();

        // Go to URL if specified
        if ($url <> "") {
            if (!EW_DEBUG_ENABLED && ob_get_length())
                ob_end_clean();
            header("Location: " . $url);
        }
    }

    //
    // Page main
    //
    function Page_Main() {
        global $Security, $Language;

        //$this->setSuccessMessage("Welcome " . CurrentUserName());
        // Put your custom codes here

    }

    // Page Load event
    function Page_Load() {

        //echo "Page Load";
    }

    // Page Unload event
    function Page_Unload() {

        //echo "Page Unload";
    }

    // Page Redirecting event
    function Page_Redirecting(&$url) {

        // Example:
        //$url = "your URL";

    }

    // Message Showing event
    // $type = ''|'success'|'failure'
    function Message_Showing(&$msg, $type) {

        // Example:
        //if ($type == 'success') $msg = "your success message";

    }
}
?>
<?php ew_Header(FALSE) ?>
<?php

// Create page object
if (!isset($custompage)) $custompage = new ccustompage();

// Page init
$custompage->Page_Init();

// Page main
$custompage->Page_Main();
?>
<?php include_once "header.php" ?>
<?php
$custompage->ShowMessage();
?>
<!-- Put your custom html here -->
<?PHP
$myarray = array(1,2,3,4,5);
echo json_encode($myarray);
?>

<?php include_once "footer.php" ?><?php
$custompage->Page_Terminate();
?>

我无法更改所有代码,因为我必须集成到我的旧项目中。在最后 7 行中,我输入了代码,当我打开此页面时,它仅输出为 [1,2,3,4,5],当我尝试将其作为

<?PHP
$myreceivearray = json_decode(file_get_contents('http://mydomain/blankpage.php'));
print_r($myreceivearray);
?>

我没有在这里得到数组。

请帮我。

4

4 回答 4

1

您可以使用 JSON 执行此操作。使用,在 myscript.php 中的方法

json_encode($yourarray) 

使用 JSON ( http://www.json.org ) 对数组进行编码。在另一个网站上,您可以使用

$myreceivearray = json_decode(file_get_contents("http://mydomain/myscript.php"));
于 2013-08-28T17:50:14.423 回答
0

对于编码:

echo json_encode($arr);

对于解码:

$arr = json_decode(file_get_contents('http://mydomain/myscript.php'), true);

不要忘记设置的第二个参数json_decode

于 2013-08-28T17:57:55.813 回答
0

http://php.net/manual/en/function.file-get-contents.php

您可以将 url 的结果作为字符串读取file_get_contents

$myreceivearray = file_get_contents(http://mydomain/myscript.php);

您将希望 myscript.php 以某种可以解析为数组json_decode或类似格式的格式回显数组。

于 2013-08-28T17:49:28.683 回答
0

您需要在第一个脚本中对数组进行编码并从另一个脚本中检索它。您可以将其编码为 JSON。我还建议相应地设置标题:

我的脚本.php

// encode response
$response = json_encode($values);

// set headers
header('Content-Type: application/json');
header('Content-Encoding: UTF-8');
header('Content-Length: ' . strlen($response));
header('Pragma: no-cache');
header('Expires: 0');

// send value
print $response;
exit();

从其他脚本中获取此内容并对其进行解码:

另一个脚本

$response = file_get_contents('http://mydomain/myscript.php');
$values = json_deocde($response);
于 2013-08-28T17:55:41.740 回答