0
Gentlemen, good night, sir! I’ve had a problem for three days without a solution.
The code below, I use to get a string as a form of authentication. The variable sPOST presents the string "Authorized" at the event Showmessage, but if I use "if sPOST = 'Authorized' then" it doesn’t work.
procedure TForm1.btnAuthClick(Sender: TObject);
var
lHTTP: TIdHTTP;
sPOST: String;
parameters: TStringList;
begin
parameters := TStringList.Create;
lHTTP := TIdHTTP.Create(nil);
try
parameters.Add('email='+edtUsuario.Text);
parameters.Add('senha='+Encode64(edtSenha.Text));
lHTTP.Request.ContentType := 'application/x-www-form-urlencoded';
//fbURL é uma CONST onde está definido a URL
sPOST := lHTTP.Post(fbURL+'/lib/consult.php', parameters);
ShowMessage(sPOST); //Aqui o sPOST recebe a string "Autorizado" ou "Negado".
//Está funcionando perfeitamente. A mensagem é exibida com a string correta.
//Mas aqui, sPOST não parece ter recebido a string,
//Pois não acata a condição.
if sPOST = 'Autorizado' then
begin
tbCtrl.ActiveTab:= tabPrincipal; //Abre aba principal
ShowMessage(sPOST); //Deveria exibir mensagem novamente como teste
end
else
begin ShowMessage('Se lascou!'); end;
finally
parameters.Free;
end;
end;
The Consult.php is like this:
$eval = $_REQUEST["email"]; //Aqui já foi utilizado como $_POST,
$sval = $_REQUEST["senha"]; //mas de nada adiantou.
$sql = "SELECT * FROM tbusuario WHERE email='$eval' AND senha='$sval'";
if($result = mysqli_query($conn, $sql)){
if(mysqli_num_rows($result) > 0){
echo "Autorizado";
mysqli_free_result($result);
} else{
echo "Negado";
}
} else{
echo "ERRO: Não foi possível executar $sql. " . mysqli_error($conn);
}
I know it seems a bit of a rough problem, but I’m struggling with it. Because this IF does not work even by a decree.
Thanks in advance for the attention and the dedicated time of all.
And what error or message appears from the result in php?
– Daniel Omine
You’re getting
"Autorizado"
orAutorizado
?– Junior Moreira
Good morning Caio. I worked a little with php and had some return problems too. One of the times I was making this kind of comparison is that you want "if sPOST = 'Authorized' then" simply the variable had a space in the front that php put. Visually in SHOWMESSAGE you won’t even see that there is this space.. but believe me.. it may be there :) . Right now it’s the only thing I can think of :). Hugs.
– Ricardo M.Souza
Daniel Omine, I’m not getting an error message. In Showmessage before IF, the sPOST variable receives the "Authorized" string, but in IF it seems not to identify the string.
– Caio Augusto
Junior Moreira, he returns Authorized even without quotation marks.
– Caio Augusto
Ricardo M. Souza, good morning! I thought about it too, but I didn’t imagine it was a fact, I didn’t want to believe it. I’m going to use "Trim" or a Stringreplace to verify it. Thank you very much for the information. In fact, that could be it. Hugs.
– Caio Augusto
Thank you all. Today I will make a few more attempts and give a position to you.
– Caio Augusto
Ricardo M. Souza, you were right. The bastard is printing like this "<body>Authorized</body>". I searched for this sequence and found that in fact it is a space (ZERO WIDTH NO-BREAK SPACE). The worst is that neither "Trim", nor "Trimleft", nor even Stringreplace is managing to fix the problem. It seems that I will have to eliminate this space before printing the return (ECHO). Finding a solution, I inform here. Thank you again.
– Caio Augusto
Oops! Thanks, @Rodrigo Rigo, but I had already tried the Trim also unsolved. GOOD in PHP. Follow the link below if someone encounters the same problem. Unicode signature (BOM)
– Caio Augusto