我正在使用php函数文件来设置全局变量的值,但是当我在其他php文件中使用include调用函数时忽略了该值(“functions.php “);如何在调用php函数期间保持变量值
我这样做:
////File1.php////
include("functions.php");
$data_person = $_POST['data_person'];//here i am getting 'data_person' from a form, it works fine
receive_DP($data_person);//Here I send the variable
show_DP();//It shows the values inside $data_person
////functions.php////
$data_person;
function receive_DP($data_person_array)
{
global $data_person;
$data_person = $data_person_array;
}
function show_DP()
{
global $data_person;
echo "name:".$data_person[0];
echo "last name:".$data_person[1];
echo "age".$data_person[2];
}
//then i go to File2.php with a FORM (input submit) and i need to keep the values in $data_person
//It is like a header, It shows personal info, It is supposed to be the values of this variable
//are set and they should be always
////File2.php//// HERE IS THE PROBLEM, I MISSED THE VALUES OF $data_persona
include("functions.php");
show_DP();//It shows nothing, just name:, last name: and age:, but not the the values
就像我说我来自一个表单标签获得的值,那么我将它们传递给File1.php与$ _ POST得到的值,它工作正常,我调用了这两个函数(receive_DP()和show_DP()),并且它的工作正常,接下来我使用按钮去File2.php,但是当我调用show_DP()函数时,值都消失了。
在会话中存储您的价值,比你可以访问他们任何你想要的地方 – 2014-09-27 04:52:55
我想到了这一点,但我不知道如何使用$ _SESSION(),请快速解释我应该怎么做,谢谢 – 2014-09-27 04:54:25
在哪个文件中获取值,以及您想要访问哪个文件。谢谢回复我我会告诉你 – 2014-09-27 04:55:22