Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

190
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!