ESP8266HTTPClient.h client.connected()


I have a large program so I can’t really post all of it here. I’ll just post what I see is relevant.
An html page is served to the browser over wifi. The page contains a few buttons, when the button is clicked, it called the same page again with parameters passed in the address line; for example http://x.x.x.x/open or x.x.x.x/close, etc.

When the page is loaded the next time, I check what is passed in the get method using this
if (header.indexOf("GET /open") >= 0) and based on the result of the if conditions, i make a note of it in a command variable. That variable’s contents is processed after the client is ‘disconnected’.

Here is the problem, i noticed that sometimes commands are executed multiple times even though i clicked once. I put some debug variables and found that while (client.connected()) is executed again, even after I closed the browser page.

I added some debug variables and found that the inside of while(client.connected) and client.available is executed even though I did not click anything.

What could be wrong?

// Load Wi-Fi library
#include <ESP8266WiFi.h>
#include <Math.h>
#include <ESP8266HTTPClient.h>

// Set web server port number to 80
WiFiServer server(80);

WiFiClient client;

void setup() {
//connect to wifi

void loop(){
  WiFiClient client = server.available();   // Listen for incoming clients

  if (client) {                             // If a new client connects,
    Serial.println("New Client.");          // print a message out in the serial port
    String currentLine = "";                // make a String to hold incoming data from the client
    while (client.connected()) {            // loop while the client's connected
            // Display the HTML web page
            client.println("<!DOCTYPE html><html>");
            client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
            client.println("<link rel=\"icon\" href=\"data:,\">");
            // CSS to style the on/Closed buttons 
            // Feel free to change the background-color and font-size attributes to fit your preferences
            client.println("<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}");
            client.println(".button { background-color: #195B6A; border: none; color: white; padding: 16px 40px;");
            client.println("text-decoration: none; font-size: 30px; margin: 2px; cursor: pointer;}");
            client.println(".button2 {background-color: #77878A;}");
            client.println(".slidecontainer { width: 100%;} </style></head>");
            // Web Page Heading
            client.println("<body><h1>Front Door Curtain Opener</h1>");

            client.println("<p><a href=\"/open\"><button class=\"button\">Open</button></a>");
            client.println("<a href=\"/close\"><button class=\"button button2\">Close</button></a></p>");              
          } else { // if you got a newline, then clear currentLine
            currentLine = "";
        } else if (c != '\r') {  // if you got anything else but a carriage return character,
          currentLine += c;      // add it to the end of the currentLine
    // Clear the header variable
    header = "";
    // Close the connection
    Serial.println("Client disconnected.");
    if (command == "MCW") {
      Move(true, curtain_max);
    } else if (command == "MCCW") {
      Move(false, curtain_max);  
    } else if (command == "CAL") {

I found my problem. I forgot to reset the command variable so when the page would load again, it would redo the same thing.