title: Newbie needs to force php page reload once
body: <p>I have this php file which I am using to control relays attached to the gpio pins of a Raspberry pi. I works well except that the icons do not update as desired when the gpio pins change state. THey do update as desired if I click the RELOAD button on the browser. I have tried using:
  location.reload(true) but it only works if I put it in the html portion of the page code as its own button. I want the location.reload(true) to execute whenever I click one of the gpio icons. Can someone help me with this? Thanks in advance from a newbie.</p>
  <p>Here is the php code I am using:</p>
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;!--TheFreeElectron 2015, http://www.instructables.com/member/TheFreeElectron/ --&gt;
  
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta charset=&quot;utf-8&quot; /&gt;
          &lt;title&gt;Antenna Relays&lt;/title&gt;
      &lt;/head&gt;
   
      &lt;body style=&quot;background-color: black;&quot;&gt;
      &lt;h1&gt;&lt;p style=&quot;color:white&quot;&gt;&lt;font size=&quot;7&quot;&gt;     
       &amp;emsp; &amp;emsp; ANTENNA SELECTOR
      &lt;/p&gt;
      
      &lt;/font&gt;&lt;/h1&gt;
      &lt;!-- On/Off button's picture --&gt;
      &lt;?php
      $val_array = array(0,0,0,0);
      //this php script generate the first page in function of the file
      for ( $i= 0; $i&lt;4; $i++) {
          //set the pin's mode to output and read them
          system(&quot;gpio mode &quot;.$i.&quot; out&quot;);
          exec (&quot;gpio read &quot;.$i, $val_array[$i], $return );
      }
      //for loop to read the value
      $i =0;
      for ($i = 0; $i &lt; 4; $i++) {
          //if off
          if ($val_array[$i][0] == 0 ) {
              echo (&quot;&lt;img id='button_&quot;.$i.&quot;' src='data/img/red/red_&quot;.$i.&quot;.jpg' onclick='change_pin (&quot;.$i.&quot;);'/&gt;&quot;);
          }
          //if on
          if ($val_array[$i][0] == 1 ) {
              echo (&quot;&lt;img id='button_&quot;.$i.&quot;' src='data/img/green/green_&quot;.$i.&quot;.jpg' onclick='change_pin (&quot;.$i.&quot;);'/&gt;&quot;);
          }    
      }
      ?&gt;
       
      &lt;!-- javascript --&gt;
      &lt;script src=&quot;script.js&quot;&gt;&lt;/script&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>