0
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 typed the URL of the site made in Wordpress, because in it I create cookies:
<?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>
Which 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();
}
?>
With linking a record from the wp_posts table to a PHP page in the theme folder.
Thank you very much for the reply. But I want to set cookies only when a login and passwords validated in AD are informed. That’s why I wanted to run a page that already exists and does the validation.
– Jothaz
Does the AD response go to a specific URL? How does WP know that it has received this information?
– Ricardo Moraleida
I edited the answer and put the code of the page that makes the validation in AD. Actually the page makes and validates and works correctly. What I need is whenever I access the site the Wordpress redirect to this page that is called authenticat.php. If the user is validated to be created cookies and access granted.
– Jothaz