2
I have a question , how do I get the id of the guy who logged in to my system? So that later he can change his data.
<?php
if (isset ($_POST ["loginUsuario_externo"])){
include_once("../controllers/Usuario_Externo_Controller.php");
$usuario_externo = new Usuario_externo_Controller;
$usuario_externo->login();
}
Login function
public function login() {
$this->usuario_externos->email($this->input->get('email'))
->senha($this->input->get('senha'));
$resultado = $this->usuario_externos->login();
if($resultado) {
session_start();
$_SESSION['login'] = $resultado;
echo '<script>window.location = "../views/externo/";</script>';
echo ('Aguarde, redirecionando.');
} else {
echo ('E-mail ou Senha incorreto(os).');
}
}
MODEL
public function login() {
$sql = "SELECT * FROM usuario WHERE email = :email AND senha = :senha AND status = 1 LIMIT 1";
$stmt = $this->conn->prepare($sql);
$stmt->bindParam(':email', $this->email, PDO::PARAM_INT);
$stmt->bindParam(':senha', $this->senha, PDO::PARAM_STR);
$stmt->execute();
return $stmt->fetch();
}
starta sessão e vrf se há sessao
<?php
session_start();
function session_checker(){
if (! isset($_SESSION['login'])){
header ("Location:../");
exit();
}
}
session_checker();
?>
<?php if (isset ($_POST ["loginUsuario_external"]){ include_once("./controllers/Usuario_externo_controller.php"); $usuario_external = new Usuario_externo_controller; $usuario_external->login(); }
– Marcus Daniel
I tried
$codigo = mysql_query("SELECT u.id, u.nome FROM usuario_externos u WHERE u.nome = '" . $_SESSION['nome'] . "';"); 
echo mysql_result($codigo, 0);
– Marcus Daniel
let me get this straight, you want to store in the session this user ID coming from the database, and then recover this session with the ID to change the data ?
– Thiago Friedman
that :) but it’s not working out at all
– Marcus Daniel
You need to edit the question and put the code that starts the session and login. we don’t know what
login()
does, not even if you did the assignment in$_SESSION
or if you signed in to the other file.– rray
I don’t understand what that line does,
$this->usuario_externos->email($this->input->get('email'))
 ->senha($this->input->get('senha'));
you are passing a password by get? in the login of your model see if email and password have any value.– rray
yes they are coming from view , get
– Marcus Daniel
print_r($stmt->fetch())
displays something? in the email bind, change :PDO::PARAM_INT
forPDO::PARAM_STR
or leave with nothing.– rray
like if I put in the controller $id=$_SESSION['id']; it was to catch the id’s carrion ? or not?
– Marcus Daniel
print_r($stmt->fetch())
broughtstdClass Object ( [id] => 1 [nome] => marcus [cpf] => [email] => [email protected] [perfil] => 1 [senha] => 6fab33feda475044 [status] => 1 [instituicao_ext] => unie )
– Marcus Daniel
Yes it is to get the id, must be
$_SESSION['login']['id']
in the doubt of aprint_r($_SESSION)
.– rray
Fatal error: Cannot use object of type stdClass as array in C:\xampp\htdocs\portoaberto\app\controllers\Usuario_Externo_Controller.php on line 45
PQ???? ehwaaeauw only error ahweauw– Marcus Daniel
Change, to
$_SESSION['login']->id
, if you want to access as an array, doreturn $stmt->fetch(PDO::FETCH_ASSOC);
– rray
rray you and the bixao vei ---------------- put in the answers that worked --
– Marcus Daniel