Ethernet Shield problem

Hello guyz!

Im trying ethernet shield now and facing the following problem: i found in the internet the following code below. When i access the page 192.168.0.24:12345 , the led diode lights on, without pressing the “on” button. Then i press “off” button, access the page again and led switches on, without pressing “on” button. Please help.

#include <SPI.h>
#include <Ethernet.h>

byte mac = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 }; //physical mac address
byte ip = { 192, 168, 0, 24 }; // ip in lan

EthernetServer server(12345); //server port

String readString;

//////////////////////

void setup(){

pinMode(4, OUTPUT); //pin selected to control
//start Ethernet
Ethernet.begin(mac, ip);
server.begin();

//enable serial data print
Serial.begin(9600);
Serial.println(“servertest1”); // so I can keep track of what is loaded
}

void loop(){
// Create a client connection
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();

//read char by char HTTP request
if (readString.length() < 100) {

//store characters to string
readString += c;
//Serial.print(c);
}

//if HTTP request has ended
if (c == ‘\n’) {

///////////////
Serial.println(readString); //print to serial monitor for debuging

//now output HTML data header
if(readString.indexOf(’?’) >=0) { //don’t send new page
client.println(“HTTP/1.1 204 Zoomkat”);
client.println();
client.println();
}
else {
client.println(“HTTP/1.1 200 OK”); //send new page
client.println(“Content-Type: text/html”);
client.println();

client.println("");
client.println("");
client.println(“Arduino GET test page”);
client.println("");
client.println("");

client.println(“

Arduino button

”);

client.println("<input type=button value=‘ON’ onmousedown=location.href=’/?on’>");
client.println("<input type=button value=‘OFF’ onmousedown=location.href=’/?off’>");

//client.println("<IFRAME name=inlineframe src=“res://D:/WINDOWS/dnserror.htm” width=1 height=1">");
client.println("<IFRAME name=inlineframe style=“display:none” >");
client.println("");

client.println("");
client.println("");
}

delay(1);
//stopping client
client.stop();

///////////////////// control arduino pin
if(readString.indexOf(“on”) >0)//checks for on
{
digitalWrite(4, HIGH); // set pin 4 high
Serial.println(“Led On”);
}
if(readString.indexOf(“off”) >0)//checks for off
{
digitalWrite(4, LOW); // set pin 4 low
Serial.println(“Led Off”);
}
//clearing string for next read
readString="";

}
}
}
}
}

How can it switch on, if it's already on?

Im new to ethernet code, where in the code the led is "already "on"" ?

Try:

          ///////////////////// control arduino pin
          if(readString.indexOf("?on") >0)//checks for on
          {
            digitalWrite(4, HIGH);    // set pin 4 high
            Serial.println("Led On");
          }
          if(readString.indexOf("?off") >0)//checks for off
          {
            digitalWrite(4, LOW);    // set pin 4 low
            Serial.println("Led Off");
          }

I suspect the string "on" appears somewhere else in the URL being passed to your server.