I need to resolve the doubt, I leave the details.
I have a class that has several related database queries with user data, to access these methods you need to check that the user is logged in, and I do this using the php initialization methods "__construct ()", indicate there if user is logged in.
<?php
class User()
{
public function __construct() {
if ( !isset($_SESSION['user']) ) {
$data = array(
'response' => false,
'message' => 'You must login to access this page'.
);
echo json_encode($data);
}
}
public function index() {
}
public function edit_profile() {
}
public function save_profile_data() {
}
}
?>
My questions:
- Using __ () construct is a good optimal resource-intensive choice?
- __ construct () is safe to use and does not allow the user to access other methods that have not indicated whether there is an encoded session variable.
.. edit_profile(), , __ construct(), ?
, , .