How can I include alertify.js in an .php file?

1

I would like to know how I can include the link plugin in an .php file, this is what I have up to the moment:

<!DOCTYPE html>
<html>
	<head>
		<link rel="stylesheet" type="text/css" href="../librerias/css/Login.css">
		<link rel="stylesheet" type="text/css" href="../librerias/responsive/GridLogin.css">
		<link rel="stylesheet" type="text/css" href="../librerias/responsive/MediaQueries_Login.css">
		<link rel="shortcut icon" href="../librerias/imagenes/Logo.png">
		<link rel="stylesheet" type="text/css" href="../librerias/css/animate.css">
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
		<title>Iniciar Sesión</title>
	</head>
	<body>
		<div class="Titulo animated2 fadeIn">
			PSeInt+
		</div>
		<!--Formulario Login-->
		<hr class="HR1 animated2 fadeIn visible-sm visible-md visible-lg" color="black">
		<div class="Login animated2 fadeIn-1">
			<form class="Formulario" method="POST" action="../php/Login.php" id="Login">
				<div class="Container">
					<div class="input-group">
						<input type="email" name="correo" class="correo" placeholder="Correo" autocomplete="off" required />
					</div>
					<div class="input-group">
						<span id="change" class="eye"></span><input type="password" name="password" class="password" id="pass" placeholder="Contraseña" autocomplete="off" required />
					</div>
					<input type="submit" class="btn-submit" value="Iniciar Sesión" />
				</div>
			</form>
			<div class="Texto">
				¿No tienes cuenta?
			</div>
			<div class="Texto2">
				<a href="Registro.html">Regístrate</a>
			</div>
		</div>
		<hr class="HR2 animated2 fadeIn visible-sm visible-md visible-lg" color="black">
		<!--Fin Formulario Login-->
		<div class="Texto3 animated2 fadeIn col-xs-12">
			Una ayuda más para fortalecer tu aprendizaje TIC
		</div>
		<script src="../js/jquery-3.2.1.min.js"></script>
		<script src="../js/changeeye.js"></script>
	</body>
</html>
<?php  
    include("Conexion.php");
    $cor = $_POST["correo"];
    $pass = $_POST["password"];
    $passEncriptado = md5($pass);
    $sql = "SELECT * FROM usuario WHERE correo='".$cor."' AND contrasena='".$passEncriptado."'";
    $resultado =  mysql_query($sql) or die ("Error");
    if (mysql_num_rows($resultado) > 0) {
        session_start();
        $_SESSION['usuSession'] = $cor;
        echo ' <script type="text/javascript"> 
            alert("Has iniciado sesión con éxito");
            window.location.href="../html/Index.php";
        </script>';
    } else {
        echo '<script type="text/javascript"> 
            alert("Correo o Contraseña incorrecta");
            window.location="../html/Login.html";
        </script> ';
    }
?>
    
asked by Spartan456 12.10.2017 в 01:27
source

2 answers

1

Good.

The way you use to login does not work well with the alertify.js library. Alertify js works well with asynchronous requests (ajax in jquery).

I recommend that you use asynchronous requests, for which you must deactivate the action of the form and put a code like the following in JS (this is an example, but there is enough code in this question ):

$(document).ready(function () {
    $('input#botonEnviar').click( function() {
        $.post( 'url_login', $('form#myForm').serialize(), function(data) {
               alertify.alert(data);
           },
           'json'
        );
    });
});

Also add resources to alertify (change according to your case):

<!-- include the script -->
<script src="{PATH}/alertify.min.js"></script>
<!-- include the style -->
<link rel="stylesheet" href="{PATH}/alertify.min.css" />
<!-- include a theme -->
<link rel="stylesheet" href="{PATH}/themes/default.min.css" />

And return a message from the server in json format or in text flat, depending on the configuration you have in the asynchronous request.

The other option is to save the messages in the session and redirect to the view correct with header('Location: '.$newURL); from php. not with window.location.href of javascript. An example is more or less like this (these types of messages are usually found on the internet as " Flash messages ", although they are generally used within a framework, they are saved in the session and only last until the next http request:

if (mysql_num_rows($resultado) > 0) {
        session_start();
        $_SESSION['usuSession'] = $cor;
        header('Location: ../html/Index.php');
        exit;
    } else {
        $_SESSION['msg'] = 'El login ha fallado';
        header('Location: ../html/Login.html');
        exit;
}

then in your Login.php view you put a code like the following:

<form>
    <!-- mensaje de login -->
    <?php if(isset($_SESSION['msg'])) {
             echo $_SESSION['msg'];
             unset($_SESSION['msg']);
          } ?>
    <input>usuario</input>
    <input>contraseña</input>
</form>

Good. This is the idea, to make it work you have to elaborate it more. It's night and for time I can not write something more decent :(

(I hope someone edits this so that it works: P)

    
answered by 12.10.2017 в 05:03
0

I do not know if I understood your question well but you can put before opening php

<script src="tucarpeta/alertify.min.js"></script>

or after closing? >

<script src="tucarpeta/alertify.min.js"></script>
    
answered by 12.10.2017 в 03:58