Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

199
Vistas
Put every POST and GET requests on hold except one specific, then continue

I need only PHP answers.

Setup : Apache Server and PHP version 7.4.

I'm working on a CAPTCHA plugin for WordPress. On that purpose, I thought I'd validate the CAPTCHA field before validating any other request.

This means I want to perform the CAPTCHA POST request before any other $_REQUEST is complete.

These other requests can be multiples, and I won't be able to handle their scripts.

I thought I'd detect if a POST or GET request has been made, then maybe call sleep() and perform my POST meanwhile.

The problem is : sleep() pauses the whole script whereas I only want the other POST and GET requests to be paused...

if ($_SERVER['REQUEST_METHOD'] === 'POST' OR $_SERVER[‘REQUEST_METHOD’] === 'GET' AND $_POST["myRequest"]) { 

    // Pause every POST and GET requests apart from $_POST["myRequest"] until $_POST["myRequest"] is performed

} else { 

    continue;

}
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You could use session and keep track of the request and save the request if $_POST['myRequest'] is not present, than load the previous request from session or a file. Like this:

<?php

session_start();

if ($_SERVER['REQUEST_METHOD'] === 'POST' OR $_SERVER[‘REQUEST_METHOD’] === 'GET') { 

   // POST myRequest has been done before
if(isset($_SESSION['.my-request.lock'])) {

    // If present remove it
    unset($_SESSION['.my-request.lock']);

    if(isset($_SESSION['my-data.json'])) {
        $my_prev_request = json_decode( $_SESSION['my-data.json'] );

        unset($_SESSION['my-data.json']);
    }

    // Process other requests

} else {

    if(isset($_POST['myRequest'])) {

        $_SESSION['.my-request.lock'] = true;

        // Do your own thing

    } else {
        // No myRequest and no file, save request data to load it after POST myRequest 
        $_SESSION['my-data.json'] = json_encode( $_REQUEST );
    }

}

} else { 

    // Display Error ?
    continue;

}
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda