Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For the sake of ease in programming it's best to use one or the other. It's best to go with PHP exclusively because:</p> <ol> <li>Massive support community at <a href="http://www.php.net/" rel="nofollow">php.net</a></li> <li>In most implementations it's faster than using the SSI because PHP is designed to do all of the processing and parsing of PHP code, whereas an SSI has to read your SHTML page (after it's written) and sift between comments and includes, then include all of the components.</li> <li>If you're including PHP pages as SSIs you're making Apache wait on PHP, whereas if you were using PHP alone it would have already delivered the page.</li> <li>You can do things with databases and a lot more with PHP.</li> <li>PHP pages can't be accessed from the server without being processed, so there is less risk of someone exploiting your code vulnerabilities if you're using standard practices.</li> <li>SSIs are plainly readable as code (and very limited).</li> </ol> <p>You can include an SSI with PHP if you're running PHP as an Apache Module, using the function <a href="http://us3.php.net/manual/en/function.virtual.php" rel="nofollow"><code>virtual()</code></a>, but why would you want to? You can <code>include()</code> just about anything into PHP. </p> <p><strong>Example</strong></p> <p>I'm going to use an account management site as an example. To make the header dynamic you'll need to find the <code>$var</code> for the page calling it (I'm going to use <code>$_SERVER['REQUEST_URI']</code>). There are several <a href="http://php.net/manual/en/reserved.variables.server.php" rel="nofollow">reserved server variables in PHP</a> that you can reference to make calls depending on circumstances. So let's say the authorized directory where all logged in pages go is called "auth" your common shell file might look like this:</p> <pre><code>&lt;?php //Check for the page the person is asking for session_start(); $root = $_SERVER['DOCUMENT_ROOT']; //Check for the "auth" directory if(preg_match('!^/?auth!',$_SERVER['REQUEST_URI'])){ //Do some check to see if they've been authenticated... this one is not secure, but you get the idea if($_SESSION['logged_in']){ //Require the correct header require_once($root.'/includes/logged-in-header.php'); } else { //They don't belong or they're not logged in, kick them back to the login page. header("Location: /login.php?e=1"); die(); } } else { //It's not an authorization required page, so show the standard header. require_once($root.'/includes/non-auth-header.php'); } //let's find out the page that's loading the shell. $pageName = preg_replace('!/([^/]+)$!',"$1",$_SERVER['SCRIPT_NAME']); switch($pageName){ /*Auth pages*/ case "billing.php": require_once($root.'/includes/billing.php'); break; case "account.php": require_once($root.'/includes/account.php'); break; case "logout.php": require_once($root.'/includes/logout.php'); break; default: //show the login page require_once($root.'/includes/login.php'); } require_once($root.'/../shell.php'); require_once($root.'/includes/footer.php'); ?&gt; </code></pre> <p>So if you were in the <code>auth</code> directory and you were not logged in, you would get the homepage. If you're in the <code>auth</code> directory on the <code>billing.php</code> page and you are logged in, the site would load the billing page.</p> <p>The <em>auth/billing.php</em> code might look like this:</p> <pre><code>require_once("$_SERVER['DOCUMENT_ROOT'].'/../shell.php'); </code></pre> <p>The <em>include/billing.php</em> code would contain all of workings of the page and it can be formatted in HTML, but you'd probably pull that stuff from a database.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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