title: Load iFrame contents via CURL request?
body: <p>I have an application that includes a file (FileX.php) which under certain conditions, will echo an iFrame to the screen which loads a tracking URL (FileY.php). In a production environment where I directly include FileX.php into the main page (FileA.php), the iFrame gets echoed to the screen and FileY.php is successfully called.</p>
  
  <p>In testing though, I need to call multiple versions of FileA.php which each include FileX.php which outputs the iFrame to call FileY.php. I am automating this large number of requests using cURL requests.</p>
  
  <p>When loading FileA.php through a cURL request, it successfully does the <code>include()</code> of FileX.php but because it is happening through cURL, the iFrame never loads it's destination (FileY.php).</p>
  
  <p>The cURL request for fileA looks something like this:</p>
  
  <p><strong>TestFile.php</strong></p>
  
  <pre><code>// URL
  $url = "http://www.example.com/FileA.php";
  
  // New Cookie file
  $ckfile = tempnam("/tmp", "CURLCOOKIE");
  
  // New Connection
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt ($ch, CURLOPT_COOKIEJAR, $ckfile);
  curl_setopt ($ch, CURLOPT_COOKIEFILE, $ckfile);  
  curl_setopt($ch, CURLOPT_COOKIESESSION, 0);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_exec($ch);
  curl_close($ch);
  </code></pre>
  
  <p><strong>FileA.php:</strong></p>
  
  <pre><code>include_once('FileX.php');
  </code></pre>
  
  <p><strong>FileX.php:</strong></p>
  
  <pre><code>echo("&lt;iframe src='http://www.example.com/FileY.php' width='0' height='0'&gt;&lt;/iframe&gt;");
  </code></pre>
  
  <p><strong>FileY.php</strong></p>
  
  <pre><code>// Contains logging stuff to log the fact that FileY.php was called.
  </code></pre>
  
  <p>Like I said, if I call FileA.php directly in my browser, FileX.php is included and FileY.php is loaded in the iFrame successfully. When I call FileA.php via cURL the iFrame doesn't load and FileY.php is never called.</p>
  
  <p>I've tried wrapping the <code>echo()</code> in FileX.php with <code>ob_start()</code> and <code>ob_end_flush()</code> to force the output but that didn't work. I've tried adding a <code>sleep(1)</code> in case maybe the request was happening too fast, no luck.</p>
  
  <p>Is there a cURL option I can change to allow this to occur? I can't figure out why it won't load the iFrame src.</p>