Hi,
this is the second time i've attempted posting to the forum... the first time it deleted the message I wrote so i'm keeping this one brief .
I am attempting to pass objects using sessions but I keep recieving the following error: "Call to a member function on a non-object". I can create the policy object, but I can't call any of it's functions...
Can anyone else see where I am going wrong?
Cheers,
Priar
========= Code follows ===========
this is the second time i've attempted posting to the forum... the first time it deleted the message I wrote so i'm keeping this one brief .
I am attempting to pass objects using sessions but I keep recieving the following error: "Call to a member function on a non-object". I can create the policy object, but I can't call any of it's functions...
Can anyone else see where I am going wrong?
Cheers,
Priar
========= Code follows ===========
PHP Code:
<?
class policy
{
var $name;
var $chain;
var $chainNum = 0;
// Initialise
function policy($name) {
$this->name = $name;
}
// Increment Chain number
function chainIncrement() {
$this->chainNum++;
}
// Add new Chain, return Chain ID
function newChain($chainName) {
$this->chainIncrement();
$this->chain[$this->chainNum] = &new chain($chainName);
return($this->chainNum);
}
function newChainRule($cnum, $protocol, $sNotAddr, $sAddr, $sMask, $sNotPort, $sPort, $dNotAddr, $dAddr, $dMask, $dNotPort, $dPort, $rulePerform) {
$this->chain[$cnum]->newRule($protocol, $sNotAddr, $sAddr, $sMask, $sNotPort, $sPort, $dNotAddr, $dAddr, $dMask, $dNotPort, $dPort, $rulePerform);
}
}
class chain extends policy
{
var $chainName;
var $rule;
var $ruleNum=0;
function chain($name="unnamed") {
$this->chainName = $name;
}
function newRule($protocol, $sNotAddr, $sAddr, $sMask, $sNotPort, $sPort, $dNotAddr, $dAddr, $dMask, $dNotPort, $dPort, $rulePerform) {
//function newRule() {
//Format addresses
//$sAddr = formatAddress($sAny, $sAddress1, $sAddress2, $sAddress3, $sAddress4);
//$dAddr = formatAddress($dAny, $dAddress1, $dAddress2, $dAddress3, $dAddress4);
$this->rule[$this->ruleNum] = new rule($protocol, $sNotAddr, $sAddr, $sMask, $sNotPort, $sPort, $dNotAddr, $dAddr, $dMask, $dNotPort, $dPort, $rulePerform);
//$this->ruleIncrement();
$this->ruleNum++;
}
}
class rule extends chain {
var $protocol;
var $sNotAddr;
var $sAddr;
var $sMask;
var $sNotPort;
var $sPort;
var $dNotAddr;
var $dAddr;
var $dMask;
var $dNotPort;
var $dPort;
var $rulePerform;
// Creates a single rule entity.
function rule($protocol, $sNotAddr, $sAddr, $sMask, $sNotPort, $sPort, $dNotAddr, $dAddr, $dMask, $dNotPort, $dPort, $rulePerform) {
$this->protocol = $protocol;
$this->sNotAddr = $sNotAddr;
$this->sAddr = $sAddr;
$this->sMask = $sMask;
$this->sNotPort = $sNotPort;
$this->sPort = $sPort;
$this->dNotAddr = $dNotAddr;
$this->dAddr = $dAddr;
$this->dMask = $dMask;
$this->dNotPort = $dNotPort;
$this->dPort = $dPort;
$this->rulePerform = $rulePerform; ;
}
}
session_start();
if(empty($_SESSION['policy'])) session_register("policy");
else (object)$policy = unserialize($_SESSION['policy']);
echo "
<form method='POST' action='$PHP_SELF'>
<input type='submit' name='addP' value='Add Policy'></input>
<input type='submit' name='addC' value='Add Chain'></input>
<input type='submit' name='addR' value='Add Rule'></input>
</form>";
if(!empty($_POST['addP'])) $policy = &new policy("ADMIN");
if(!empty($_POST['addC'])) $cNum = $policy->newChain("Input");
if(!empty($_POST['addR'])) $policy->newChainRule($_POST['cNum'], "IP", "!", "192.168.0.0", "24", 0, 0, 0, 0, 0, 0, 0, "DENY");
echo "Policy Name: " . $policy->name. "<br>";
echo "Number of chains: " . $policy->chainNum . "<p>";
for($i=1; $i<=count($policy->chain); $i++) {
echo "Chain Name: " . $policy->chain[$i]->chainName . "<br>";
echo "Number of rules: " . $policy->chain[$i]->ruleNum . "<br>";
for($j=0; $j<$policy->chain[$i]->ruleNum; $j++) {
echo "Protocol: " . $policy->chain[$i]->rule[$j]->protocol . "<br>" .
"SourceAddress: " . $policy->chain[$i]->rule[$j]->sAddr . "<p>";
}
}
$policy = serialize(&$policy);
echo "Serialized policy: " . $policy;
?>
Comment