Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Move the PHP code outside the body's id attribute for readability, and use <code>else if</code>. Make sure your code isn't vulnerable to injection by sanitizing or validating input from <code>$_GET</code>. For example:</p> <pre><code>&lt;?php function isValidID($x) { return preg_match('/^[A-Z][-_.A-Za-z0-9]$/i', $x); } if (isset($_GET['section']) &amp;&amp; isValidID($_GET['section'])) { $bodyID = $_GET['section']; } else if (isset($_GET['page']) &amp;&amp; isValidID($_GET['page'])) { $bodyID = $_GET['page']; } else { $bodyID = 'home'; } ?&gt; ... &lt;body id="&lt;?php echo $bodyID; ?&gt;"&gt; </code></pre> <p>Alternatively,</p> <pre><code>&lt;?php function isValidID($x) { return preg_match('/^[A-Z][-_.A-Za-z0-9]$/i', $x); } $bodyID='home'; foreach (array('section', 'home') as $key) { if (isset($_GET[$key]) &amp;&amp; isValidID($_GET[$key])) { $bodyID = $_GET[$key]; break; } } ?&gt; ... &lt;body id="&lt;?php echo $bodyID; ?&gt;"&gt; </code></pre> <p>In this case, I'd use the first, unrolled version. If you had to check more input keys, use the loop-based approach.</p> <p>If you decide you want both page &amp; section in the ID, you can try something like:</p> <pre><code>&lt;?php function isValidID($x) { return preg_match('/^[A-Z][-_.A-Za-z0-9]$/i', $x); } if (isset($_GET['page']) &amp;&amp; isValidID($_GET['page'])) { $bodyID = $_GET['page']; } else { $bodyID = 'home'; } if (isset($_GET['section']) &amp;&amp; isValidID($_GET['section'])) { $bodyID .= '_' . $_GET['section']; } ?&gt; ... &lt;body id="&lt;?php echo $bodyID; ?&gt;"&gt; </code></pre>
    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