controlling led with php web page and Arduino Ethernet Shield

i want to control led with on and off buttons on php web page the moment i press on the php file called (index.php) send '1'( and '0' if off) to text file called (ledstatus.txt) then a file called (ledstatus.php) will connect with the arduino
now the problems are :
when i opened the serial monitor to check my output was :

connecting...
connected
HTTP/1.1 200 OK
Date: Wed, 12 Mar 2014 14:50:23 GMT
Server: Apache
Vary: Accept-Encoding
Connection: close
Content-Type: text/html

1
disconnecting.

first problem : i pressed on so it sends '1' then it disconnected
second problem : when i closed the serial monitor window the arduino resets it self

my codes:

( index.php )

<? if (isset($_POST['status'])) { $fh = fopen("ledstatus.txt", 'w') or die("can't open file"); $on = $_POST['status']; fwrite($fh, $on); fclose($fh); } else { $fh = fopen("ledstatus.txt", 'r'); $on = fread($fh, 1); fclose($fh); } ?> value="1">On value="0">Off

(ledstatus.php)

<? $fh = fopen("ledstatus.txt", 'r'); echo fread($fh, 1); fclose($fh); ?>

(Arduino script )

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

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress server(173,254,123,155);
String host = "www.jccdhr.org";
String page = "/opelec/ledstatus.php";

IPAddress ip(192,168,133,199);

EthernetClient client;

void setup() {

Serial.begin(9600);
pinMode(8, OUTPUT);
//pinMode(4, OUTPUT);
Ethernet.begin(mac, ip);

// if (Ethernet.begin(mac) == 0) {
// Serial.println("Failed to configure Ethernet using DHCP");

//Ethernet.begin(mac, ip);
// }

delay(1000);

Serial.println("connecting...");

if (client.connect(server, 80))
{
Serial.println("connected");
client.print("GET ");
client.print(page);
client.println(" HTTP/1.0"); // here I can adjust as suggested, using HTTP/1.1 and force a connection close
client.print("Host: "); // needed in my case (virtualserver)
client.println(host);
// client.println("GET /opelec/ledstatus.php?status= HTTP/1.1 200 OK");
// client.println("Host: www.jccdhr.org");
// client.println("Connection: close");
client.println();
}
else
{
Serial.println("connection failed");
}
}

void loop()
{
while (client.connected()) {
if (client.available())
{
boolean currentLineIsBlank = true;
String buffer = "";
char c = client.read();
Serial.print(c);
buffer+=c;

if (c == '1') {

currentLineIsBlank = true;
// buffer="";
// else if (c == '\r')
// if(buffer.indexOf("GET /?status=0")>=0)
digitalWrite(8,HIGH);
}
else if (c == '0')
{
digitalWrite(8,LOW);
}

// if(buffer.indexOf("GET /?status=2")>=0)
// digitalWrite(4,HIGH);

// if(buffer.indexOf("GET /?status=3")>=0)
// digitalWrite(4,LOW);

else {

currentLineIsBlank = false;
}
}

if (!client.connected())
{
Serial.println();
Serial.println("disconnecting.");
client.stop();

//while(true);
}
}
}

ledstatus.txt is an empty file
and all the three files ledstatus.php , index.php , ledstatus.txt are on the webserver

and by the way excuse my english :sweat_smile:

thnx :slight_smile: