我有 2 个 PHP 文件。
第一个称为 data.php 并具有
<?php
$get = $_GET;
if (isset($get['getBoxes']) && $get['getBoxes'] == 'what-we-do') {
$boxes = array(
array(
'title' => 'e-commerce',
'color' => '#ff910f',
'content' => 'As your E-Commerce partner we will identify your specific needs, build solutions that will make your operations stronger, and provide a powerful web presence.',
),
array(
'title' => 'mobile & social',
'color' => '#ffd11a',
'content' => 'Be it iOS, Android or Windows Phone, we can accommodate your specific needs for your ideal mobile application.',
),
array(
'title' => 'open source cms',
'color' => '#39a91f',
'content' => 'Every good open-source CMS system allows for great flexibility to be customized and extended. Let us help you build yours.',
),
array(
'title' => 'software development',
'color' => '#17b5ff',
'content' => 'Our development services help you address evolving business and technology challenges by building applications tailored to meet your business requirements.',
),
array(
'title' => 'interactive design and usability',
'color' => '#6b6bff',
'content' => 'We are a full-service user interface design firm offering information architecture, interaction design, and full visual design.',
),
);
echo json_encode($boxes);
exit;
}
if (strpos($_SERVER['REQUEST_URI'], basename(__FILE__)) !== false) {
header("HTTP/1.1 404 File Not Found", 404);
exit;
}
从另一个名为 html.php 的 PHP 文件中,我想使用 $boxes 数组,但我不知道如何访问它,因为它在 $get 中。
正如我所说,这种类型的操作通常是通过 Ajax 完成的。
现在,您可以像这样欺骗文件
data.php
:1. 在
html.php
您构建一个 pseudo_get,然后执行包含,如下所示。
2 英寸
data.php
您将不得不稍作修改。您必须评论或删除此行:
由于 的值
GET
实际上是从 发送的html.php
。您也可以像这样构建自己的
$_GET
变量html.php
:只有在这种情况下,您必须修改以下行
data.php
:这种情况表明,在这种情况下,它总是
data.php
需要调用它的地方的值才能正常工作。您是否已经尝试过 require_once?
根据php手册
据我了解,您的代码 $boxes 将根据
因此,如果不满足条件,则不会定义 $boxes 并小心退出,因为这将结束脚本的执行