title: Write data from Arduino to server using PHP
body: <p>I asked a related question a few days ago and now tried to achieve my goal using a different method, but it didnt work either. I cant get my head around why, so if you have any idea what I could have missed, please leave a comment :)</p>
  
  <p>In my current setup, the Arduino (with an Ethernet Shield 2) tries to start a php GET script on the server and send it a simple value.
  Here is my code, only trying to send the value 42:</p>
  
  <pre><code>#include &lt;Ethernet2.h&gt;           //library for ethernet functions
  #include &lt;SPI.h&gt;
  #include &lt;Client.h&gt;             //library for client functions
  
  
  // Ethernet settings
  byte mac[] = {0x90,0xA2,0xDA,0x0D,0x8B,0xB3};  //Replace with your Ethernet shield MAC
  byte ip[] = { 192,168,1,105};  //The Arduino device IP address
  byte subnet[] = { 255,255,255,0};
  byte gateway[] = { 192,168,0,1};
  IPAddress server(134,119,45,10);        // IP-adress of server arduino sends data to
  
  EthernetClient client;
  
  bool connected = false;
  
  void setup(void)
  {
  
  Serial.begin(9600);
  Serial.println("Initializing Ethernet.");
  delay(1000);
  Ethernet.begin(mac);
  Serial.println("Status ");
  analogReference(INTERNAL);
  
  }
  
  void loop(void){
  
  if(!connected)
  {
  Serial.println("Not connected");
  if (client.connect(server,80))
  {
      connected = true;
      Serial.print("Status is ");
      Serial.println("42");
      Serial.println();
      Serial.println("Sending to Server: ");
  
      client.print("GET /php_get_write.php?state=");
      Serial.print("GET /php_get_write.php?state=");
      client.print("42");
      Serial.print("42");
  
      Serial.println();
      client.println();
      client.println("HTTP/1.1\r\n");
      Serial.println();
      Serial.println("HTTP/1.1\r\n");
      client.println("Host: localhost\r\n");
      Serial.println("Host: localhost\r\n");
      client.println();
      client.println("User-Agent: Arduino\r\n");
      Serial.println("User-Agent: Arduino\r\n");
      client.println("Accept: text/html\r\n");
      Serial.println("Accept: text/html\r\n"); 
      client.println();
      Serial.println();
      delay(1000);
  }
  else
  {
      Serial.println("Cannot connect to Server");
  }
    }
    else
    {
      delay(1000);
      while (client.connected() &amp;&amp; client.available())
  {
      char c = client.read();
      Serial.print(c);
  
  
  }
  Serial.println();
  client.stop();
  connected = false;
  }
   }
  </code></pre>
  
  <p>On the server, I have the script that gets the value and writes it to a file:</p>
  
  <pre><code>&lt;?php
  $file = "status.txt";
  $status = $_GET["state"];
  echo "Getting data from Arduino and writing to file...";
  echo $_GET["state"];
  file_put_contents ($file,$status);
  ?&gt;
  </code></pre>
  
  <p>And a script that reads the value from the file and shows it:</p>
  
  <pre><code>&lt;?php
  echo ("Status of toilets:");
  $data = file_get_contents("status.txt");
  echo ($data);
  ?&gt;
  </code></pre>
  
  <p>I am pretty sure that the php code is correct and that the problem lies in the configuration of the arduino or the server. Since I only have limited know-how on these subjects I hope that you have an idea of what is going wrong and guide me on the right path!
  May it be the php.ini configuration? Or is something with the arduino code?</p>
  
  <p>Thanks for help in advance!</p>