Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在php中将数据带到另一个页面_Php_Oop - Fatal编程技术网

如何在php中将数据带到另一个页面

如何在php中将数据带到另一个页面,php,oop,Php,Oop,作为问题,我可以在下面的代码中使用$\u SESSION,但我想在不使用$\u SESSION的情况下这样做,有什么建议吗? 我是在php中使用oop的新手 PHP(第1页): next.php $next = $_SESSION["test"]; 您可以将变量存储在类中,然后使用getter方法获取该数据。 file1.php if(isset($_POST['submit'])){ $data = new MyData($_POST['test']); } class MyD

作为问题,我可以在下面的代码中使用
$\u SESSION
,但我想在不使用
$\u SESSION
的情况下这样做,有什么建议吗? 我是在php中使用oop的新手

PHP(第1页):

next.php

$next = $_SESSION["test"];

您可以将变量存储在类中,然后使用getter方法获取该数据。 file1.php

if(isset($_POST['submit'])){
     $data = new MyData($_POST['test']);
}


class MyData{
     private $data = '';

     function __construct($test){
          ***some process***
          $data = $test;
     }
     function getData() {
         return $this->data;
     }
}
file2.php

    include file1.php;
    echo $data->getData();

我声明了一个函数并返回到
next.php的第1页

function showContent($content){
      if(!empty($content)){
            return $content;
      }
      return false;
}
然后在
class.php
上,我声明一个getter作为先生的答案。
在第1页,我添加了一行
$next=showContent($data->getData())

关于这个问题,已经有很多答案了-。请记住,php是无状态的。该站点解决方案的可能副本是在第二页使用
$\u GET
,但我需要传递许多数据,而不仅仅是一个数据作为我的问题。
$\u COOKIE
不安全。这对我来说不起作用,但我使用另一种方法来做。谢谢你的回答。
    include file1.php;
    echo $data->getData();
function showContent($content){
      if(!empty($content)){
            return $content;
      }
      return false;
}