0
I have a question in my application. I would like to retrieve data from one class that has been set in another. However when I do data recovery it turns null.
Here is my object
class geraHash {
private $codigo;
//Aqui é o encapsulamento dos dados
public function setCodigo($codigo){
$this -> codigo = $codigo;
}
public function getCodigo(){
return $this->codigo;
}
//Aqui é o método que gera o código de verificação
public function GeraCodigo($qtd){
$Caracteres = 'ABCDEFGHIJKLMOPQRSTUVXWYZ0123456789';
$QuantidadeCaracteres = strlen($Caracteres);
$QuantidadeCaracteres--;
$Hash=NULL;
for($x=1; $x <= $qtd; $x++){
$Posicao = rand(0,$QuantidadeCaracteres);
$Hash .= substr($Caracteres,$Posicao,1);
}
return $Hash;
}
//Aqui é o método que faz a verificacao e onde eu gostaria de obter o dado setado
public function VerificaCod($cod) {
$codVerificacao = $this->getCodigo();
//if ($cod === $codVerificacao){
echo $codVerificacao, $cod;
return TRUE;
//}
}
}
There is another class where I send to the email and I select the data in my object.
<?php
include 'geraHash.php';
class loginDAO {
public function recuperaSenha(loginVO $login){
$mysqli = new mysqli("localhost", "root", "", "bdMeuBanco");
$stmt = $mysqli ->prepare("SELECT emailLogin FROM tblLogin WHERE emailLogin = ?");
$stmt ->bind_param("s", $p1);
$p1 = $login ->getEmailLogin();
$stmt ->execute();
if($stmt ->num_rows >=0){
$geraHash = new geraHash(); //Aqui ocorre a instancia de um novo objeto
$cod = $geraHash ->GeraCodigo(6); // Aqui eu chamo o método que gera o cod que vai ser passado na msgm via email
$geraHash->setCodigo($cod); //Aqui eu seto o dado no objeto
$arquivo = "<html><head><meta charset='utf-8'></head><style type='text/css'> body{font-family: monospace;color: darkgray;font-size: 16px;width: 500px;}h3{color: black;}</style><body>Enviamos esse código para que possa redefinir sua senha.<br><h3>$cod</h3> <br>Se você não solicitou a redefinição de sua senha ignore este email!</body></html>";
$destino = $login->getEmailLogin();
$assunto = "Redefinição de senha";
require_once('class.phpmailer.php'); //chama a classe de onde você a colocou.
$mail = new PHPMailer(); // instancia a classe PHPMailer
$mail->IsSMTP();
//configuração do gmail
$mail->Port = '465'; //porta usada pelo gmail.
$mail->Host = 'smtp.gmail.com';
$mail->IsHTML(true);
$mail->Mailer = 'smtp';
$mail->SMTPSecure = 'ssl';
//configuração do usuário do gmail
$mail->SMTPAuth = true;
$mail->Username = '[email protected]'; // usuario gmail.
$mail->Password = 'password'; // senha do email.
$mail->SingleTo = true;
// configuração do email a ver enviado.
$mail->From = "[email protected]";
$mail->FromName = "meu dominio";
$mail->addAddress($destino); // email do destinatario.
$mail->Subject = $assunto;
$mail->Body = $arquivo;
$mail ->CharSet = "UTF-8";
if(!$mail->Send()){
echo "Erro ao enviar Email:" . $mail->ErrorInfo;
}
return TRUE;
}
}
}
And my last file receives the data that was passed via email to make the check
<?php
include 'loginDAO.php';
$loginDAO = new loginDAO();
if(NULL !== filter_input(INPUT_POST, "btnConfirmar2")){ //Aqui verifica se o botão existe para receber uma acao
$geraHash = new geraHash();
$cod = filter_input(INPUT_POST, "userCodPass");
if($geraHash ->VerificaCod($cod)){
echo "Funcionou";
}
}
I have come to the conclusion that the object is not receiving the value because I am instantiating the object twice in different classes. For that I would need to reuse the first instance, someone knows how I can do it?
p.s: I have used global
but I didn’t get a result.
The problem is in calling
VerificaCod()
?– rray
No, it’s the return of the die ->
$codVerificacao = $this->getCodigo();
– Jessy
He returns me null
– Jessy
I suspect that the beginning of the problem is the last bit of code. In it should have a call
setCodigo()
– rray
the
setCodigo()
is in the fileloginDAO
– Jessy
See the result of
var_dump($geraHash->getCodigo())
beforeif($geraHash ->VerificaCod($cod)){
– rray
I did what he said, he called me back
null
:(– Jessy