Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>PHP is reloading its own page with a reference to the content to be added. The $_GET method is the natural way to do this, but there are two other options which spring to mind.</p> <p>1) Use a session variable to reference the page to be loaded. 2) Use AJAX so that the page is never actually reloaded. Instead, you load the new content into the page via AJAX.</p> <p>If you want to go the session variable route, then something like this will do it.</p> <pre><code>&lt;?php session_start(); if($_GET['page']) { // set session variable $_SESSION['page'] = $_GET['page']; // redirect to hide URL change header('Location: includes.php'); } ?&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt; PHP Includes &lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;h1&gt; This is the home page &lt;/h1&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="includes.php?page=page1"&gt;Page1&lt;/a&gt; &lt;/li&gt; &lt;li&gt;&lt;a href="includes.php?page=page2"&gt;Page2&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="includes.php?page=page3"&gt;Page3&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/body&gt; &lt;/html&gt; &lt;div style='width:300px; height: 200px; border: 1px solid #000;'&gt; &lt;?php error_reporting(E_ALL ^ E_NOTICE); $page = $_SESSION['page']; $pages = array('page1', 'page2', 'page3'); if (!empty($page)) { if(in_array($page,$pages)) { $page .= '.php'; include($page); } else { echo 'Page not found. Return &lt;a href="includes.php"&gt;home&lt;/a&gt;'; } } else { include('page1.php'); } ?&gt; &lt;/div&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