I basically have 3 important files right now.
I want to use a function from the DB class in the LOGIN class.
These are my files. I tried including the DB class but then I would be declaring it twice, which you cant do.
—- index.php —-
— Which displays the content —
<?php
session_start();
include './libs/database.php';
$mysql = new Database();
include './libs/login.php';
$login = new Login();
$mysql->connect("---", "user", "pass");
$mysql->usedatabase("db");
?>
<!DOCTYPE html>
<html>
<body>
<div id="wrapper">
CONTENT GOES HERE
</div>
</body>
</html>
---
---login.php ---
class Login{
public function isLoggedIn(){
if(isset($_SESSION['user_id'])){
return true;
}else{
return false;
}
}
public function UserLogin($email,$password){
// login function
$DB->selectwhere(...);
}
public function securePassword($pass){
$pass = md5($pass);
return $pass;
}
}
---
--- database.php ---
class Database{
//Database Functions
}
Make the securePassword() function in Login a static function so you can call it without an instance of the Login class.
Login::securePassword()