vendredi 30 avril 2021

script won't execute if statement [closed]

I'm trying to make a script where a variable can only be entered 2 times and if the variable is entered for the 3rd time the script is supposed to not let the user do that. And to do this I'm having PHP write different strings to a file such as "used1" and "used2" etc when a function is called. The file creation part works and writing until "used2" works fine but the script will never write "used3" into the file and won't display the echo message. Instead, it starts writing from "used1" again.

Here's my code:

$a = 'users/'.$playerName.'.txt';
            if (strpos(file_get_contents($a), 'used1') === false) {
                $fp = fopen('users/'.$playerName.'.txt', 'w');//opens file in append mode
                fwrite($fp, 'used1');  
                fclose($fp);  
                var_dump(strpos(file_get_contents($a), 'used1'));
                
                echo "File appended successfully";
                $wsr->sendCommand("goldencrates givekey $playerName csgo 1");
                $wsr->disconnect(); //Close connection.
                die();
            }
            if (strpos(file_get_contents($a), 'used2') === false) {
                $fp = fopen('users/'.$playerName.'.txt', 'w');//opens file in append mode
                fwrite($fp, 'used2');  
                fclose($fp);  
                var_dump(strpos(file_get_contents($a), 'used2'));
                
                echo "File appended successfully";
                $wsr->sendCommand("goldencrates givekey $playerName csgo 1");
                $wsr->disconnect(); //Close connection.
                die();
            }
            if (strpos(file_get_contents($a), 'used3') === false) {
                $fp = fopen('users/'.$playerName.'.txt', 'w');//opens file in append mode
                fwrite($fp, 'used3');  
                fclose($fp);  
                var_dump(strpos(file_get_contents($a), 'used3'));
                
                echo "You cannot get anymore rewards today!";
                $wsr->sendCommand("goldencrates givekey $playerName csgo 1");
                $wsr->disconnect(); //Close connection.
                die();
            }

Aucun commentaire:

Enregistrer un commentaire