log out when you close the browser page

hello guys, I have a web server running on my arduino with the code below and it created a login page, but the problem is when I login page and then close the browser without clicking log off if I reopen the page will still be logged wonder if I can do to close the page when the browser make it automatic logout ..

//#include <MemoryFree.h>//biblioteca para fazer teste de memoria
#include <Ethernet.h>
#include <SPI.h>
#include <avr/pgmspace.h>

byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x49, 0xD6 };
byte ip[]    = {192,168,1,111}; // endereço de IP 
byte gateway[]  = {192,168,1,1}; // gateway
byte subnet[] = {255,255,255,0}; // mascara de rede

boolean proceed = true; //Flag que permite a exibição da página protegida

EthernetServer server(8080); //porta do servidor


 String state = String(3);

 String readString  = String(30); //string para endereço de dados

int LED = 3,LED2=4; // led1=pino3 led2=pino4
int bot=9, ent1=0,a=0;
int CONT=0,CONT2=0;          // contadores para imagens das lampadas
char c = 0;           // variavel que recebe dados
char command[2] = "\0";  // command

void painel();


void setup(){
  //start Ethernet
  Ethernet.begin(mac, ip, gateway, subnet);
  //Set pin 4 to output
  pinMode( bot, INPUT);
  pinMode(LED,OUTPUT);
  pinMode(LED2,OUTPUT);
  digitalWrite(LED, HIGH);
  digitalWrite(LED2, HIGH);
  
Serial.begin(9600);
  
 }


void loop(){
 


/*habilitar teste de memoria
Serial.print("freeMemory()=");
  Serial.println(freeMemory());
  delay(2000);
*/
    //Serial.print("int.");
    
    ent1=digitalRead(bot);
   if( ent1==HIGH && a==0 ){
      digitalWrite(LED, LOW);
      a=1;
      CONT=1;
      delay(500);
  }else{
  if(a==1 && ent1==HIGH ){
    digitalWrite(LED, HIGH);
      a=0;
      CONT=0;
      delay(500);    
  }
  }

  EthernetClient client = server.available();
  if (client) {
    if (client.connected()){   
      char c = client.read();
      if (readString.length() < 30){
         readString += c;
      }
      Serial.print(c);
      if (c == '\n') {
       readString.trim();
        if(readString == ("GET /?a8a=ihouse123 HTTP/1.1")){
          proceed = true;
          painel();
       
       }else{
            //Pagina de login
            client.println(F("HTTP/1.1 200 OK"));
            client.println(F("Content-Type: text/html; charset=utf-8"));
            client.println();
            client.println(F("<html>"));
            client.println(F("<body>"));
            client.println("<title>ihouse | Login</title>");
            client.println(F("

"));
            client.println(F("






"));
            client.println(F("<center>"));
            
            client.println(F("<form action='./' method='get'>"));
            client.println(F("<center>"));
            client.println("<img src=\"http://img844.imageshack.us/img844/999/h1gv.jpg\">");
            client.println(F("</center>"));
            client.println(F("

"));
            client.println(F("<span style=\"color:#00979c;\"><span style=\"font-family:lucida sans unicode,lucida grande,sans-serif;\"><b>Senha:</b></span></span>"));
            client.println(F("

"));
            client.println(F("<input type='password' name='a8a' />"));
            client.println(F("<input type='submit' value='OK' />"));
            client.println(F("</center>"));
            client.println(F("</form>"));
           client.print(F("</body>"));
          client.print(F("</html>"));
          a=1;
            
       }     
    
       //limpa string para proxima leitura
       readString="";
       //finaliza cliente
       client.stop();
  
    }
  }
}
}



void painel(){
 
   while(proceed){
  EthernetClient client = server.available();
  
  boolean current_line_is_first = true;

  if (client) {
    
    boolean current_line_is_blank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        
        if (c == '\n' && current_line_is_blank) {
         
          client.println(F("HTTP/1.1 200 OK"));
          client.println(F("Content-Type: text/html"));
          client.println();
           client.println(F("<html>"));
             client.println(F("<body>"));

         
          //client.println("<META HTTP-EQUIV=REFRESH CONTENT=5 URL=>");
          
          // webpage title
          client.println("<title>ihouse | Painel</title>");
          client.println(F("






"));
         
          client.println("<center><img src=\"http://img191.imageshack.us/img191/1640/rmcw.jpg\"></center>");// FUNDO BOTOES
          
          
         if (CONT == 1) { 
           client.println("<center><p><h2><font color=#00979c><font face=arial>Lampada do quarto:</font></font><img src=\"http://img32.imageshack.us/img32/608/axkm.jpg\"></h2></p></center>");
           
                     }
          else { 
           client.println("<center><p><h2><font color=#00979c><font face=arial>Lampada do quarto:</font></font><img src=\"http://img826.imageshack.us/img826/448/h5oq.jpg\"></h2></p></center>");
           
                                }  
          if (CONT2 == 1) { 
           client.println("<center><p><h2><font color=#00979c><font face=arial>---:</font></font><img src=\"http://img32.imageshack.us/img32/608/axkm.jpg\"></h2></p></center>");
          }
          else { 
           client.println("<center><p><h2><font color=#00979c><font face=arial>---:</font></font><img src=\"http://img826.imageshack.us/img826/448/h5oq.jpg\"></h2></p></center>"); 
          }  
          // botões
          
           client.print(F("



"));
          client.println(F("<form  method=get name=form>"));
          client.println(F("<center>"));
          client.println(F("<button name=b value=1 type=submit style=height:40px;width:100px>QUARTO ON</button>"));
          client.println(F("<button name=b value=2 type=submit style=height:40px;width:100px>QUARTO OFF</button>
"));
          client.println(F("<button name=b value=3 type=submit style=height:40px;width:100px>---</button>"));
          client.println(F("<button name=b value=4 type=submit style=height:40px;width:100px>---</button>
"));
          client.print(F("

")); 
          client.println(F("<button name=b value=5 type=submit style=height:40px;width:100px>Logoff</button>")); 
          client.println(F("</center>"));    
          client.println(F("</form>
"));
          client.print(F("</body>"));
          client.print(F("</html>"));
            
          client.println("<meta http-equiv=\"refresh\" content=\"10;URL=/?b=5\">");
          
          break;
        }
        if (c == '\n') {
          
          current_line_is_first = false;
          current_line_is_blank = true;
        } 
        else if (c != '\r') {
          
          current_line_is_blank = false;
        }
        
        if (current_line_is_first && c == '=') {
          for (int i = 0; i < 1; i++) {
            c = client.read();
            command[i] = c;
          }
          // controle dos LEDs 
          if (!strcmp(command, "1")) {
            digitalWrite(LED, LOW);
            CONT=1;
            a=1;
          }
          else if (!strcmp(command, "2")) {
            digitalWrite(LED, HIGH);
            CONT=0;
            a=0;
          }
          else if (!strcmp(command, "3")) {
            digitalWrite(LED2, LOW);
            CONT2=1;
          }
          else if (!strcmp(command, "4")) {
            digitalWrite(LED2, HIGH);
            CONT2=0;
          }
          else if (!strcmp(command, "5")) {
             proceed = false;
            client.println(F("HTTP/1.1 200 OK"));
            client.println(F("Content-Type: text/html; charset=utf-8"));
            client.println();
            client.println(F("<html>"));
            client.println(F("<body>")); 
            client.println("<meta http-equiv=\"refresh\" content=\"0.0001;URL=\">");
            client.println(F("</html>"));
            client.println(F("</body>")); 
                                          

          }
          
        }
      }
    }
    // da ao browser tempo para receber dados
    delay(1);
    client.stop();
    
    }
 }
}

How is the Arduino supposed to know that you've closed your browser?

          client.println("<meta http-equiv=\"refresh\" content=\"10;URL=/?b=5\">");

If you are using a refresh, you can tell if the client isn't connecting every 10 seconds. If the sketch doesn't get a request from the client for 20 seconds, log out the client.

you can tell if the client isn't connecting every 10 seconds.

Hoe do you identify one client? Specifically, how do you distinguish one client from another?

OP: That code doesn't look very secure. Once one client logs in, your system is wide open. ANY client can then issue requests, and your Arduino will implement them.

Typically, the server returns a token to a logged in client. Then, the client supplies that token on every get request. No token, and the GET request results in the login page appearing.

How do you identify one client? Specifically, how do you distinguish one client from another?

Oops! My bad. :blush: I have that capability, but it is a custom modification to my ethernet library.

And PaulS is correct. This is not very secure.