title: PHP when countdown runs out
body: <p>So I have a countdown timer that grabs a .php file when the clock hits 0. Only problem is, the php file is opening in a new window. I would like it to be displayed at the bottom of the page somehow.</p>
  
  <p>I don't know anything about javascript or AJAX. Only php and html. Can anyone show a newbie what to do?</p>
  
  <blockquote>
  <pre><code>&lt;!--START COUNTDOWN TIMER SCRIPT--&gt;
                            &lt;br&gt;
                            &lt;script type="text/javascript"&gt;
  
                            window.onload = function() {
  countDown('my_div1', 'timerunout.php', 4); } function countDown(elID, output, seconds) {
  var elem = document.getElementById(elID),
      start = new Date().getTime(), end = start+seconds*1000,
      timer = setInterval(function() {
          var now = new Date().getTime(), timeleft = end-now, timeparts;
          if( timeleft &lt; 0) {
              document.location.href = output;
              clearInterval(timer);
          }
          else {
              timeparts = [Math.floor(timeleft/60000),Math.floor(timeleft/1000)%60];
              if( timeparts[1] &lt; 10) timeparts[1] = "0"+timeparts[1];
              elem.innerHTML = "When the Clock hits Zero...&lt;br&gt; "+timeparts[0]+":"+timeparts[1];
          }
      },250); // the lower this number, the more accurate the timer. 250 recommended }
  
                            &lt;/script&gt;
  
  
                            &lt;center&gt;
                            &lt;font color="#FF0000"&gt;&lt;b&gt;&lt;h1&gt;
                            &lt;div id="my_div1"&gt;
                            &lt;/div&gt;
                            &lt;/h1&gt;&lt;/b&gt;&lt;/font&gt;
                            &lt;/center&gt;
                            &lt;!--END COUNTDOWN TIMER SCRIPT--&gt;
  </code></pre>
  </blockquote>
  
  <hr>
  
  <p>Ok so I have a countdown timer on index.php, when it hits 0... it opens another php file into the bottom of the page using AJAX. Let's call this timerunout.php</p>
  
  <p>Problem is this... in that Php file is a link. 
  At the end of that link needs to be an affiliate ID attached to the end of it.</p>
  
  <p>That affiliate ID is only detected when someone types their username at the end of the address in the index.php. Any suggestions?</p>
  
  <p>Here's the code for index.php</p>
  
  <blockquote>
    <p> <br> 
        window.onload = function() { 
            countDown('my_div1', 'timerunout.php', 4); 
        } </p>
  
  <pre><code>function countDown(elID, output, seconds) {
      var elem = document.getElementById(elID);
      start = new Date().getTime(), end = start+seconds*1000,
      timer = setInterval(function() {
          var now = new Date().getTime(), timeleft = end-now, timeparts;
          if( timeleft &lt; 0) {
              //This code creates the AJAX object, which will then be used to send it.
              var xmlhttp;
              if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
                  xmlhttp=new XMLHttpRequest();
              } else {// code for IE6, IE5
                  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
              }
  
              //This code parameterizes the object to point at your page in an asynchronous way.
              xmlhttp.open("GET","timerunout.php?s1=username",true);
              xmlhttp.send(); //Once all parameters are set, send it on it's way.
  
  
              //Callback. Once the request is in one of it's stages, this will be called.
              xmlhttp.onreadystatechange=function() {
                  //Request done and fetching the page successful?
                  if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200) {
                      //Sets the HTML of my_div1 to whatever was in timerunout.php
                      elem.innerHTML=xmlhttp.responseText;
                  }
              }
              clearInterval(timer);
          } else {
              timeparts = [Math.floor(timeleft/60000),Math.floor(timeleft/1000)%60];
              if( timeparts[1] &lt; 10) timeparts[1] = "0"+timeparts[1];
              elem.innerHTML = "When the Clock hits Zero...&lt;br&gt; "+timeparts[0]+":"+timeparts[1];
          }
      } ,250); // the lower this number, the more accurate the timer. 250 recommended  } &lt;/script&gt; &lt;center&gt;
      &lt;div id="my_div1"&gt;&lt;/div&gt; &lt;/center&gt; &lt;!--END COUNTDOWN TIMER SCRIPT--&gt;
  </code></pre>
  </blockquote>
  
  <p>and here's the timerunout.php</p>
  
  <blockquote>
    <p>      
  
  <pre><code>    //
      // Maybe check $s1 is indeed valid
      //
  
      $newurl = sprintf('/join.php?id=%s', urlencode($_GET['s1']));
      $coaching = sprintf('/live/webinar-register.php?id=%s',
  </code></pre>
    
    <p>urlencode($_GET['s1']));
                  ?>      </p>
  </blockquote>
  
  <p>So basically what I'm saying is that in index.php,
  <code>username</code> in this line needs to be coming from what the user types in their address bar.</p>
  
  <pre><code>xmlhttp.open("GET","timerunout.php?s1=username",true);
  </code></pre>