title: Arduino and PHP web page
body: <p>I am trying to get a PHP web page to take temperature readings from the <a href="http://arduino.cc/en/Main/ArduinoBoardUno" rel="nofollow">Arduino Uno</a> with an Ethernet shield, through an Apache web server. I am writing the temperature reading to a text file and then taking it from there onto the <a href="http://en.wikipedia.org/wiki/PHP" rel="nofollow">PHP</a> webpage, using two PHP files.</p>
  
  <p>However, I cannot get the temperature reading to the text file. I am not sure if the Arduino code is incorrect and is not sending the temperature reading or if the PHP code is incorrect and not taking in the temperature reading. I know the Arduino and the webpage are communicating as I am reading back from the webpage to the serial monitor.</p>
  
  <h3>Arduino code</h3>
  
  <pre><code>#include &lt;Ethernet.h&gt;  //Library for Ethernet functions
  #include &lt;SPI.h&gt;
  #include &lt;Client.h&gt;    //Library for client functions
  
  byte MACaddress[] = {0x90, 0xA2, 0xDA, 0x0D, 0x8B, 0xB3};  //Replace with your Ethernet shield MAC address
  byte IPaddress[] = { 192,168,1,102};  //The Arduino device IP address
  byte subnet[] = { 255,255,255,0};
  byte gateway[] = { 192,168,0,1};
  IPAddress server(192,168,1,100);      // IP address of server the Arduino sends data to
  EthernetClient client;
  bool connected = false;
  
  int sensorInPin = 0;
  float temperature = 0;
  
  void setup(void)
  {
  
      Serial.begin(9600);
      Serial.println("Initializing Ethernet.");
      delay(1000);
      Ethernet.begin(MACaddress);
  
      Serial.println("LM35 Sensor ");
      analogReference(INTERNAL);
  }
  
  void printTenths(int value)
  {
      // Prints a value of 123 as 12.3
      Serial.print(value / 100);
      Serial.print(".");
      Serial.println(value % 10);
  }
  
  void loop(void)
  {
      int span = 20;
      int aRead = 0;
      for (int i = 0; i &lt; span; i++)
      {
          aRead = aRead + analogRead(sensorInPin);
      }
      aRead = aRead / 20;
      temperature = ((100 * 1.1 * aRead)/99) * 10;
  
      if (!connected)
      {
          Serial.println("Not connected");
          if (client.connect(server,80))
          {
              connected = true;
              //int temp = analogRead(A1);
              Serial.print("Temp is ");
              Serial.println(temperature);
              Serial.println();
              Serial.println("Sending to Server: ");
  
              client.print("GET /arduino.php?t0=\n");
              Serial.print("GET /arduino.php?t0=\n");
              client.print(temperature);
              Serial.print(temperature);
              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>
  
  <h2>Arduino.php code</h2>
  
  <pre><code>&lt;?php
      echo date("d.m.Y-H:i:s");
      file_put_contents("C:\Folder\Mechatronics Application\Semester 2\Project               \Hello.txt",$_GET['t0']);
  ?&gt;
  </code></pre>
  
  <h3>Index.php code</h3>
  
  <pre><code>&lt;?php
      echo date("d.m.Y-H:i:s");
      $string1 = file_get_contents("C:\Folder\Mechatronics Application\Semester 2\Project\Hello.txt");
      echo $string1;
  ?&gt;
  </code></pre>