I have 2 PHP files.
The first is called data.php and has
<?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;
}
And from a second PHP file called html.php I want to use the $boxes array but I don't know how to access it since it's inside $get.
As I was saying, this type of operation is usually done through Ajax.
Now, you can literally trick the file like
data.php
this:1. in
html.php
You build a pseudo_get and then do the include, as follows.
2 in
data.php
You would have to make a slight modification. You must comment or delete this line:
Since the value of
GET
would actually be sent fromhtml.php
.You could also build your own variable
$_GET
inhtml.php
like this:Only in that case, you would have to modify this line of
data.php
:What this situation demonstrates is that always , in this type of case,
data.php
it will need values from where it is invoked, in order to work properly.Have you already tried require_once?
According to the php manual
And as I understand your code $boxes will be defined depending on
so if the condition is not met then $boxes will not be defined and be careful with exit because that will end the execution of the script