1

I have an website working on Apache 2.4 server and coded with PHP7. Time to time I can't retrieve any data from $_REQUEST variable. Its not specific to a page but for all 200+ pages I have in the website, $_REQUEST variable stops working and whatever I post to the pages get lost. This happens so randomly. Sometimes all ok for a month but sometimes this happens twice a day.

When I restart Apache, problem gets fixed but I try to understand why this happens.

To be able to test it I coded a simple PHP script as below

<html>
<head></head>
<body>
    <form action="test.php?GetVar=GetVarExists" method="post">
        <input type="hidden" name="PostVar" value="PostVarExists">
        <input type="submit">
    </form>

    <?php
    $PostVar=$_REQUEST["PostVar"];
    $GetVar=$_REQUEST["GetVar"];
    $LocalVar = "LocalVarExists";

    echo "PostVar: $PostVar <br>";
    echo "GetVar: $GetVar <br>";
    echo "LocalVar: $LocalVar <br>";
    ?>
</body>
</html>`

Normally, page shows the result below when I click submit

PostVar: PostVarExists GetVar: GetVarExists LocalVar: LocalVarExists

When $_REQUEST stops working randomly, the page show the result below when I click submit

PostVar: GetVar: LocalVar: LocalVarExists

Then I have to restart Apache to get it fixed. I couldn't debug more than that and I'm not an expert for PHP and Apache. I would appreciate if someone give me an idea what could be the problem.

Thanks

Sofyan Thayf
  • 1,322
  • 2
  • 14
  • 26
ripref
  • 11
  • 3
  • Maybe helpful:- https://stackoverflow.com/questions/2142497/whats-wrong-with-using-request – Alive to die - Anant Apr 05 '19 at 08:20
  • That's definitely not supposed to happen, and it's not normal. Have you tried reading the raw input stream just to see how that looks? Do that with `echo file_get_contents("php://input");` – Amunium Apr 05 '19 at 08:25
  • 4
    Not to be nasty or picky, but things usually not happen randomly in coding (not even random itself). That's the point in debugging: finding what is different when behaviour suddenly differs. Like logging variables and comparing the output – Kaddath Apr 05 '19 at 08:25
  • Just curious, which version of PHP7 are you running? – KIKO Software Apr 05 '19 at 08:39
  • @KIKOSoftware I'm using 7.0.30 version – ripref Apr 05 '19 at 09:59
  • @AlivetoDie thank you I'll read though – ripref Apr 05 '19 at 09:59
  • @Amunium I'll try that next time it stops working again. Thank you – ripref Apr 05 '19 at 10:00
  • @Kaddath I agree with you. I dont think its related coding. maybe a server setting, maybe memory issue or maybe antivirus locks it but definately not code related since it happens at same time for all 200+ pages. but I dont know how to debug it. – ripref Apr 05 '19 at 10:02
  • PHP 7.0.30 is EOL (if I'm reading this correctly): https://www.php.net/eol.php You need to upgrade. There's a very small change that upgrading will also solve your problem. PHP 7.2.17 seems like a good choice. – KIKO Software Apr 05 '19 at 10:08

0 Answers0