2 回答
![?](http://img1.sycdn.imooc.com/533e4c9c0001975102200220-100-100.jpg)
TA贡献1765条经验 获得超5个赞
<?php
$value="this value";
include 'file2.php';
include 'file1.php';
这$value将对两个类都可见。
所以只需使用file2.php两者中的变量就已经是可见的file2.php
![?](http://img1.sycdn.imooc.com/5333a0780001a6e702200220-100-100.jpg)
TA贡献1810条经验 获得超4个赞
SESSIONS 是这里的另一个选项,会话变量可用于跨页面访问这些变量。
<?php
// file1.php
ob_start();
session_start();
$month= $_REQUEST['month']; // check for sql injections and XSS
$year= $_REQUEST['year']; // check for sql injections and XSS
$_SESSION['month'] = $month;
$_SESSION['year'] = $year;
?>
删除硬编码值并替换为会话,
<?php
ob_start();
session_start();
//file2.php
/*
remove hardcoded values and replace with
$month= '5';
$year = '2019';
*/
$month= $_SESSION['month'];
$year = $_SESSION['year'];
/*
your logic goes blow
*/
?>
- 2 回答
- 0 关注
- 122 浏览
添加回答
举报