Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p>So is it possible to determine which page is calling the include with PHP?</p> </blockquote> <p>No idea. But if it is possible it will be via <code>$_SERVER</code>. Put this in your header.php for testing:</p> <pre><code>&lt;?php echo '&lt;pre&gt;'; print_r($_SERVER); echo '&lt;/pre&gt;'; </code></pre> <p>However, if the page is being requested as <code>*.html</code> with Server-Side Includes I can't even begin to predict what kind of havoc this is going to play with PHP Sessions. I have doubts that <code>session_start()</code> will ever be able to set proper headers in this context, or if the PHP session cookie will ever be sent to the client or be passed through SSI back to PHP.</p> <p>As far as I am aware/concerned SSI should only ever be used to include static content or dynamic content that does not rely on any sort of interaction with the user, including something as basic as if they're logged in or not. SSI is a kludge between static and dynamic pages and should be referred to as "kinda-sorta-dynamic-but-not-really".</p> <p>Short answer: SSI is going to be a massive pain in the ass, ditch it and just use PHP <code>include()</code>.</p> <p><strong>Edit:</strong> Your page would look something like this at the most basic level, and is not really any more complex than using SSI. If you took a more <a href="http://www.onextrapixel.com/2012/03/14/a-detailed-overview-of-the-model-view-controller-mvc-coding-structure/" rel="nofollow">MVC-oriented</a> approach [namely the C and V parts] it would become more manageable:</p> <pre><code>&lt;?php session_start(); // other initialization ?&gt;&lt;html&gt; &lt;head&gt; &lt;!-- relevant header calls --&gt; &lt;head&gt; &lt;body&gt; &lt;div id="body"&gt; &lt;?php if($_SESSION['is_logged_in']){ echo(/*logged out header*/); } else { echo(/*logged in header*/); } ?&gt; &lt;!-- actual page content --&gt; &lt;/div&gt; &lt;?php include("footer.php"); ?&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
 

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