The classes are all very basic at this point, not much done in them, but here is the relevent code, all of the variables coming from the main script are set in an include file. I should also mention that I have only been working with PHP for about 6 months and I had the brilliant idea to try to learn classes on my own.
First the two calling lines from the main script:
Code: Select all
$secureLogin=new authentication();
$secureLogin->connectDatabase($dbServer,$dbUserName,$dbPwd,$database,'open');
$secureLogin->connectDatabase('','','','','close');
The authentication class:
Code: Select all
final class authentication{
//properties
public $referer; //page user came from
public $ipAddress; //user ip address
private $database; //used for instance of DBAccess class
//methods
public function checkReferer(){
//checks referer against provided value
return($this->referer==$_SERVER['HTTP_REFERER']);
}//end checkReferer()
public function checkIPSingle(){
//checks user ip address against provided value
return($this->ipAddress==$_SERVER['REMOTE_ADDR']);
}//end checkIPSingle()
public function connectDatabase($dbServer,$dbUserName,$dbPwd,$database,$method){
//connects and disconnects from MySQL database using provided data, method is
// used to indicate what to do, acceptable values are 'open' and 'close'
if ($method=='open'){
$this->database=new DBAccess();
$this->database->dbServer=$dbServer;
$this->database->dbUserName=$dbUserName;
$this->database->dbPwd=$dbPwd;
$this->database->database=$database;
$this->database->dbConnect('open');
}else if($method=='close'){
$this->database->dbConnect('close');
}else{
print '<h1>CRITICAL ERROR: you must use open or close for method</h1>';
}//end if
}//end connectDatabase()
}//end authentication class
The database access class:
Code: Select all
class DBAccess{
//properties
public $dbServer;
public $dbUserName;
public $dbPwd;
public $database;
public $dbConn;
//methods
public function dbConnect($method){
//used to open and close connections to the database, method can be only
// 'open' or 'close'
if ($method=="open"){
$this->dbConn=mysql_connect($this->dbServer,$this->dbUserName,$this->dbPwd) or die('Could not connect: '.mysql_error());
mysql_select_db($this->database) or die('Could not select database.');
}else{
mysql_close($this->dbConn);
}//end if
}//end dbConnect()
}//end DBAccess class
The DBAccess class is a modification of a function that I have been using for the last two months to handle database access, and it works quite well.
As I said, the above seems to work in a standard http session, but, as soon as I shift it over to an SSL session, the last call from the main script throws an error.