I have 2 pages and one class, index.php, loggedin.php and userclass.php.
**
Index.php
**
require 'userclass.php';
$user = new User();
if($user->loggedin = true){
header("location: loggedin.php");
die();
}
**
loggedin.php
**
require 'userclass.php';
$user = new User();
if($user->loggedin = false){
header("location:index.php");
die();
}
if(isset($_POST['logout'])){
$user->logout();
header("location:index.php");
}
**
Userclass.php
**
public $loggedin = false;
public function logout(){
session_destroy();
$this->loggedin = false;
return $this->loggedin;
}
I’m unable to logout or visit the index page without being redirected to loggedin.php.
I have a feeling it may be something to do with my scope of the logged in variable, or where it is being used?
Sorry I’m new to OO php and would appreciate any help.
Thanks
p.s. some other irrelevant functions were left out however if you think they may be relevant I’ll post them too.
You need to use two equal signs to do a comparison, otherwise you’re doing an assignment:
The way you have it written, you’re setting
loggedinequal totrueevery time.