PHP에서 타사 COM 객체로 작업하고 있으며 향후 서버 호출에서 객체에 액세스하기 위해 객체를 세션 변수에 저장하려고합니다.PHP 세션 문제
내가 세션에서 개체를 저장하는 경우 :
$_SESSION['collItem'] = $collItem;
을 나는 그것이 $_SESSION['collItem']
통해 메서드와 속성의 inmediately 정의 이후에 액세스 할 수 있습니다.
그러나 나중에 서버를 호출 할 때 $_SESSION['collItem']
을 사용하려고하면 다시 액세스 할 수 없습니다.
여기에 명확한 몇 가지 코드를 작성합니다.
방법은 내 스크립트 "functions.php"에서 COM 개체를 initailize하기 : 방법
public function setAppData() {
try {
$appD = new COM('ASData.CASDataApp');
$appD->InitMasterData(true, 1, 91);
$appD->DateMask = 'ymd';
$_readDB = $appD->InitApp($this->readDB());
} catch (Exception $e) {
$err = 'Connection error: ' . htmlentities(addslashes(strip_tags($e->getMessage())));
$this->setError($err);
return false;
}
$appD->appPath = str_replace('\app\include', '', __DIR__);
$this->iniciarCollections($appD);
$this->appData = $appD;
}
전화를 내 스크립트 "edit_json.php"에서 :
require_once('functions.php');
if (!session_id()) {
session_start();
}
// We recover $mbw object saved in session and initialize COM object
if (isset($_SESSION['mbw'])) {
$mbw = unserialize($_SESSION['mbw']);
}
$mbw->setAppData();
$appData = $mbw->getAppData();
$_SESSION['appData'] = $appData;
내가 액세스 $의 _SESSION을 시도하는 경우 [ 'appData'] COM 초기화 후 즉시 문제없이 작업 할 수 있지만 $ _SESSION [ 'appData']에 저장된 whith $ appData 객체 :
if (!session_id()) {
session_start();
}
$appData = $_SESSION['appData'];
// I can't work with $appData object if I don't initialize it again
COM 개체를 다시 초기화하면 모든 변경 사항을 잃어 버리기 때문에 좋은 해결책이 아닙니다.
모든 스크립트를 다음으로 시작합니다. 'if (!session_id()) { session_start(); } ' – TraXX