0
I’ve been searching for information for a long time to unravel the mysteries of POO (PHP) and I can’t find them.
I would like to know how to call a certain function in another file by running a form, example;
<<login.php>>
<form name="login" method="post" action="funcoes.php">
<h1>Acesso</h1>
<p>Nick
<input type="text" id="user" placeholder="Insira o nome de usuario" name="user"></p>
<p>Senha
<input type="password" id="senha" placeholder="Insira a senha" name="senha"></p>
<p class="lead">
<button type="submit">Entrar</button>
</p>
</main>
</form>
<<php functions.>>
<?php
class conta{
function autenticacao(){
$user=htmlspecialchars($_POST["user"]);
$senha=htmlspecialchars($_POST["senha"]);
$sql="select * from operador where usuarioOp='$user'";
$resultado=mysqli_query($link,$sql);
$fim=mysqli_fetch_array($resultado);
if($senha=$resultado){
echo"log_ok";
$_SESSION['id']=$fim['idOp'];
$_SESSION['nick']=$fim['usuarioOp'];
$_SESSION['nome']=$fim['nomeOp'];
$_SESSION['rank']=$fim['rankOp'];
$_SESSION['nick']=md5('seg'.$_SERVER['REMOTE_ADDR'].$_SERVER['HTTP_USER_AGENT']);
header('location:login.php');
}else {
echo"log_erro";
session_unset();
header('location:index.php');
}
}
function cadastro(){
$user=htmlspecialchars($_POST["user"]);
$senha=htmlspecialchars($_POST["senha"]);
$nome=htmlspecialchars($_POST["nome"]);
$nasc=htmlspecialchars($_POST["nascimento"]);
$cpf=htmlspecialchars($_POST["cpf"]);
$rank=htmlspecialchars($_POST["rank"]);
$result=mysqli_query($link,"insert into operador (usuarioOp, senhaOp, cpfOp, nomeOp, nascimentoOp, rankOp) values ('$user', '$senha', '$cpf', '$nome', '$nasc', '$rank' )")or die (mysqli_error());
if($result){
$_SESSION["nome"]=$nome;
$_SESSION["user"]=$user;
echo "cad_ok";
header("Location:online.php");
}else {
echo "cad_erro";
header("Location:login.php")
}
}
}
?>
I did just that and I can not find anything related to my doubt on the internet, I would like to use only PHP to call the function Appliance in the archive php functions. by requesting Ubmit on the login.php. before I was using IF and so on, but I decided to try to find new methods to speed up the procedures.. because staying doing if for each function becomes difficult... a lot of similar function with different data collection.
I thank anyone who can help me. And I hope that this will solve some doubts of others in the future, if it is solved. Big hug.
It is interesting to keep in mind that just using a class does not mean that it is using the POO paradigm. The paradigm has principles that must be followed, such as, but not limited to, abstraction and inheritance. Without it, you just created a class to replace something that could be functions. In fact, the way it is structuring the code, it would make more sense to use the procedural paradigm, with functions, than to take risks in the POO.
– Woss
Hello my friend certainly did not know how to ask me about, is that I imagined that most who knew of POO (PHP) would answer this question with a ease... rs Actually I wanted to perform even functions, but I was not successful. If you can/know methods to help me, I’ve been searching for ways to do this for a long time, I read and reread the PHP documentation and I couldn’t do it. Hug.
– Yan Goulart