I have a PHP page that connects to a WebService and performs user validation in AD.
I would like this page to be called when I typed in the URL of the site made in WordPress, because I create cookies in it:
<?php
if(isset($_POST['login']) && isset($_POST['senha'])) {
if (empty($_POST['login']) || empty($_POST['senha']) ) {
$error = 'Preencha todos os campos.';
} else {
$client = new SoapClient('http://endereco-do-webservices/servico.asmx?WSDL', array('login'=> "usuario-servico",'senha'=> "******"));
$vars = $client->Autentica(array('login' => stripslashes($_POST['login']), 'senha' => $_POST['senha']));
if($vars->AutenticaResult == true) {
$var = $_POST['login'];
$dominio = preg_split('/\\/', $var, -1, PREG_SPLIT_NO_EMPTY);
if($dominio[0]==$var){
$dominio[0] = 'meu-dominio';
$dominio[1] = $var;
}
$search = $client->BuscaLogin(array('dominio'=>$dominio[0],'login' => $dominio[1]));
$email = $search->BuscaLoginResult->Mail;
$nome = $search->BuscaLoginResult->Nome;
$dominiofin = $search->BuscaLoginResult->Dominio;
setcookie("MyAuth", 'true', time()+50400);
setcookie("MyMailAuth", $email, time()+50400);
setcookie("MyNomeAuth", $nome, time()+50400);
setcookie("MyDominioAuth", $dominiofin, time()+50400);
header("location: /meu-site");
} else {
$error = 'Login inválido';
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta content="IE=10" http-equiv="X-UA-Compatible" />
<title>Verifica Login</title>
<!--link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/auth.css"-->
<!--link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/css/less.css"-->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body class="auth">
<?php if($error) {
echo '<script>window.alert("'.$error.'");</script>';
} ?>
<img src="<?php bloginfo('template_url'); ?>/img/mylogo.png" alt="">
<form method="post">
<input type="text" name="login" placeholder="Login" />
<input type="password" name="senha" placeholder="Senha" />
<input type="submit" value="Entrar">
</form>
</body>
</html>
That are validated in the header.php of the theme:
<?php
if(!isset($_COOKIE['AGAuth'])) {
$url = bloginfo('template_url');
header('Location:'.$url.'?page_id=73');
exit();
}
?>
By connecting a record of the wp_posts table to a PHP page in the theme folder.