Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Thank you all for your answers and collaboration. Although none of the answers did exactly what I was looking for, they showed me other ways to approach this issue and guided me to decide what method to use.<br> I came up with what I think is the simpliest way to do this:</p> <ol> <li>I set my folder structure as: <strong>pages/aside</strong> and <strong>pages/main</strong> </li> <li>I set up an array($asides) with the <strong>aside</strong> files as the <em>keys</em> and the <strong>main</strong> content files as the <em>values</em>.</li> <li>Then I check if the requested file exists in the <strong>main</strong> folder.</li> <li><strong>If it doesn't exist</strong>, I redirect the user to the 404 page. <strong>If it does exist</strong>, I loop through <em>$asides</em> to see which <em>aside</em> is asigned to that <em>main</em> content page.</li> <li>If it doesn't belong to any of the establisged <em>asides</em>, then I include the <strong>default</strong> aside.</li> </ol> <pre><code>$asides = array( 'aside1' =&gt; array('page1', 'page2', 'page3', 'page4'), 'aside2' =&gt; array('page5', 'page6') ); $page = (!empty($_GET['p'])) ? sanitize($_GET['p']) : 'page1'; if (file_exists("pages/main/{$page}.php")) { foreach ($asides as $key =&gt; $value) { if (in_array($page, $asides[$key])) { $aside = $key; break; } } if (!isset($aside)) $aside = 'default'; ?&gt; &lt;div id="aside"&gt;&lt;?php require "pages/aside/{$aside}.php"; ?&gt;&lt;/div&gt; &lt;div id="main"&gt;&lt;?php require "pages/main/{$page}.php"; ?&gt;&lt;/div&gt; &lt;?php } else { header('Location: ?p=404'); } </code></pre> <p><br> The bounty goes to <strong>Madara Uchiha</strong> because in my opinion, his answer is simple an effective. Thanks again to all of you who helped me with this issue.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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