Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p>I'd like to avoid doing any needless HTTP requests on my site to improve performance</p> </blockquote> <p><code>include</code> also makes an HTTP request when you supply an HTTP URI to it, so instead of the client's asynchronous include (for example using AJAX or an iframe) you do it synchronously on the server, therefore making the page load even slower.</p> <p>So while the include may work as intended (you want to include the <strong>output</strong>, right?), it will definitely not speed up your site.</p> <blockquote> <p>the PHP I'm calling expects some parameters to be passed via HTTP GET. I'd like to keep it that way since I also want to be able to access those PHP files from other places.</p> </blockquote> <p>Then alter those files and set the appropriate variables before including them. Or even better, refactor it into functions. For example, if the file you want to include looks like this:</p> <pre><code>$username = $_GET['username']; print "User: $username"; </code></pre> <p>Then refactor into a function and store in a separate file:</p> <pre><code>function PrintUsername($username) { print "User: $username"; } </code></pre> <p>And call it appropriately:</p> <pre><code>include('printusername.php'); PrintUsername($_GET['username']); </code></pre> <p>(You might want to throw in an <code>isset()</code> here and there.) Now you can alter your code that also needs this output:</p> <pre><code>include('printusername.php'); PrintUsername($someOtherVariable); </code></pre> <p>Now you don't have to rely on URL or <code>$_GET</code> or <code>include</code> magic, but simply use all functions as they're meant to.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload