Ethernet Shield and SD card... question in programming

Let's suppose we dont use the SD card of the Ethernet Shield and we have the following segment of code:

void loop()
{
EthernetClient client = server.available(); // try to get client

if (client) {
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();

if (c == '\n' && currentLineIsBlank) {

// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println();
// send web page
client.println("");
client.println("");
client.println("");
client.println("Arduino Web Page");
client.println("");
client.println("");
client.println("

Hello from Arduino!

");
client.println("

A web page from the Arduino server

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

if (c == '\n') {

currentLineIsBlank = true;
}
else if (c != '\r') {

currentLineIsBlank = false;
}
}
}
delay(1);
client.stop();
}
}

Now, let's suppose we use the SD card...

The above code is changed to the following:

if (client) {
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();

if (c == '\n' && currentLineIsBlank) {

// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println();
// send web page
webFile = SD.open("index.htm"); // open web page file which is found in the micro SD card
if (webFile) {
while(webFile.available()) {
client.write(webFile.read()); // send web page to client
}
webFile.close();
}
break;
}
// every line of text received from the client ends with \r\n
if (c == '\n') {
// last character on line of received text
// starting new line with next character read
currentLineIsBlank = true;
}
else if (c != '\r') {
// a text character was received from client
currentLineIsBlank = false;
}
} // end if (client.available())
} // end while (client.connected())
delay(1); // give the web browser time to receive the data
client.stop(); // close the connection
} // end if (client)
}

with storing in the SD card the following index.htm file:

Arduino Web Page

Hello from Arduino

A web page from the Arduino SD card server.

Namely, all the commands such as:
client.println("

A web page from the Arduino server

");
are changed to:

A web page from the Arduino server

inside the index.htm file.

But what if we have, inside the Web Page code, lines such as:

........................

//controls the Arduino if you press the buttons
if (readString.indexOf("?button1on") >0){
digitalWrite(led, HIGH);
LED = HIGH;

}

if (readString.indexOf("?button1off") >0){
digitalWrite(led, LOW);
LED = LOW;
}

.............

client.println("<a href="/?button1on"">Turn On LED");
client.println("<a href="/?button1off"">Turn Off LED");

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

client.println("LED is now: ");

if(LED == HIGH)
{
client.println("ON");
}
else
{
client.println("OFF");
}

..........

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

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

//clearing string for next read
readString="";

}

}
}
}
}

What do we do in such a case? Could u tell me how the Arduino code and the index.htm file would be done????

I don't think it would be practical to embed Arduino C code in the web page. It would require a C code interpreter in the Arduino.

The only reason I thought something like this is that when compiling (without using the SD card) the Arduino says: "Low memory available. Stability problems may occur". (Even so, everything works fine.)

So I thought to store the web page file in the SD card.

Delta_G:
Yeah, that's not going to work. The html file is for html, it can't control arduino.

You could embed some special characters and let your routine that is reading the file and writing it to the client see those and know to do something else. I've done something like that before. But you can't put C code in your html file. That's not going to do anything but generate errors.

Could u give me an example of how such a thing is done? This could reduce memory issues?