Jump to content

BANEAR USUARIO DESDE WEB


ZeroCrazy

Recommended Posts

Hola, comunidad!

Os presento un script para vuestra web. Es sencilla y rápida. Si tenéis alguna duda que pueda resolver, encantado estaré. Y si necesitáis que os ayude con código sobre funciones, me lo comentáis también.

Imágenes de cómo sería en PC y PHONE:

Debes iniciar sesión para ver el contenido del enlace en esta publicación.

<?php
    error_reporting(0);
    // $conn = mysqli_connect('HOST', 'USERNAME', 'PASSWORD');
    if($_GET['form'] == 'submit'){
        
        $usuario = htmlspecialchars(filter_var($_POST['usuario'], FILTER_SANITIZE_STRING));
        $section = htmlspecialchars(filter_var($_POST['section'], FILTER_SANITIZE_STRING));
        if($section == 'ban'){$action='BLOCK';}else{$action='OK';}
        if(empty($usuario) || empty($section)){

            echo "<script>M.toast({html: 'Todos los campos son obligatorios', classes: 'red'})</script>";

        } else {

            mysqli_query($conn, "UPDATE account.account SET status = '".$action."' WHERE login = '".$usuario."'");
            echo "<script>M.toast({html: 'La cuenta ha sido baneada', classes: 'green'})</script>";

        }

    } else {
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Light Codetech Mt2 APP</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
    <style>
        body {
            background-color: #424242 !important;
        }
        .w-100 {
            width: 100%;
        }
    </style>
</head>
<body>
    <div id="server-results"></div>
    <section class="container">
        <div class="row">
            <div class="col s12 m8 offset-m2 l6 offset-l3">
                <div class="card white z-depth-0">
                    <div class="card-content black-text">
                    <span class="card-title center">Gestión de acceso</span>
                    <p class="center">Desde Ligh Codetech Mt2 APP puedes gestionar el acceso de un usuario.</p>
                    <br>
                        <div class="row">
                            <form id="formulario" action="<?php echo basename(__FILE__); ?>?form=submit" method="POST" class="col s12">
                                <div class="input-field col s12 m6">
                                    <input id="last_name" name="usuario" autofocus type="text" class="validate" required>
                                    <label for="last_name">Usuario</label>
                                </div>
                                <div class="input-field col s12 m6">
                                    <select name="section" class="browser-default" required>
                                        <option value="" disabled selected>Selecciona una acción</option>
                                        <option value="ban">Banear</option>
                                        <option value="unban">Desbanear</option>
                                    </select>
                                </div>
                                <div class="input-field col s12 m12">
                                    <button type="submit" class="waves-effect waves-light btn-large w-100 z-depth-0 #212121 grey darken-4">Enviar</button>
                                </div>
                            </form>
                        </div>
                        <p class="center grey-text">Desarrollado por <a href="https://metin2zone.net/index.php?/profile/1061-zerocrazy/">ZeroCrazy</a> | <a href="https://codetech.es">Codetech</a></p>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
    <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
    <script>
    $("#formulario").submit(function(event){
        event.preventDefault();
        var post_url = $(this).attr("action");
        var request_method = $(this).attr("method");
        var form_data = $(this).serialize();
        
        $.ajax({
            url : post_url,
            type: request_method,
            data : form_data
        }).done(function(response){
            $("#server-results").html(response);
        });
    });
</script>
</body>
</html>
<?php } ?>

He subido este script porque he visto el de

Debes iniciar sesión para ver el contenido del enlace en esta publicación.
que era del 2012 desactualizado.

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...