我使用两页第一页从url获取值并显示一些内容。我在第二页中包含第一页但不应显示第一页但我必须访问第一页中使用的第二页中的值。 第一页的编码
first.php
在utl中,该值作为first.php传递?Logid = 7773& shiftdate = 2013-01-04& shiftid = 146& pshift = 1& tsid = 1& dctype = timebased
<?php
$Logid=$_GET['Logid'];
$ShiftDate=$_GET['shiftdate'];
$ShiftID=$_GET['shiftid'];
$PShift=$_GET['pshift'];
$TsID=$_GET['tsid'];
$DcType=$_GET['dctype'];
// below this some process is carried out
sec.php
<?php
ob_start();
include('first.php');
ob_end_clean();
echo $Logid;
echo $ShiftDate;
echo $ShiftID;
echo $PShift;
echo $TsID;
echo $DcType;
?>
该值未显示在第二页中.. 说我如何访问第二页中的值。 请帮助我 谢谢你!!!
答案 0 :(得分:0)
删除ob_end_clean();
,看看会解决它。
ob_end_clean - 清理(擦除)输出缓冲区并关闭输出缓冲
<强> sec.php 强>
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
include("first.php");
?>
尝试上面的代码,看看它是否返回任何错误。
答案 1 :(得分:0)
在PHP中“通常”访问数据的最佳方式(除了小的,非实质性的片段)是通过封装。您可以将这些值放入对象中。然后,您将能够在sec.php上访问它们:
first.php:
<?php
class pageData {
public $Logid;
public $ShiftDate;
public $ShiftID;
public $PShift;
public $TsID;
public $DcType;
public function __construct() {
$this->Logid = $_GET['Logid'];
$this->ShiftDate = $_GET['shiftdate'];
$this->ShiftID = $_GET['shiftid'];
$this->PShift = $_GET['pshift'];
$this->TsID = $_GET['tsid'];
$this->DcType = $_GET['dctype'];
}
}
$pageData = new pageData();
?>
sec.php:
<?php
include('first.php');
echo $pageData->Logid;
// ...
echo $pageData->DcType;
?>
答案 2 :(得分:0)
您正尝试将页面中GET设置的值传递给第二页,对不对?如何尝试使用会话。
您可以启动session并定义将在浏览器打开且会话仍处于活动状态时存储的值。所以:
first.php
<?php
// Starting the session
session_start();
$_SESSION['Logid'] = $_GET['Logid'];
$_SESSION['ShiftDate'] = $_GET['shiftdate'];
$_SESSION['ShiftID'] = $_GET['shiftid'];
$_SESSION['PShift'] = $_GET['pshift'];
$_SESSION['TsID'] = $_GET['tsid'];
$_SESSION['DcType'] = $_GET['dctype'];
?>
sec.php
<?php
echo $_SESSION['Logid'];
echo $_SESSION['ShiftDate'];
echo $_SESSION['ShiftID'];
echo $_SESSION['PShift'];
echo $_SESSION['TsID'];
echo $_SESSION['DcType'];
?>
并使用
session_unset();
session_destroy();
终止会话并销毁全局变量($ _SESSION)中的数据。如果您需要格外谨慎,可以使用:
session_unset();
session_destroy();
session_write_close();
setcookie(session_name(),'',0,'/');
session_regenerate_id(true);
确保一切都被彻底摧毁。如果你问我但是必要时使用它会有点矫枉过正。
希望它有所帮助!