if exists in array } else {
<p>I currently use the following script that checks if a page exists in my array and then opens it, else it opens my error.php</p>

<pre><code>&lt;?php
    $page = $_GET['page'];
    $pages = array('p_1',
                   'p_2',
                   'p_3',
                   'error');

    if (!empty($page)) {
     if(in_array($page, $pages)) {
        $page .= '.php';
        require_once('../' . $page . '');
    }
     }
    else {
        require_once('../error.php');
    }
?&gt;
</code></pre>

<p>Accidentally (until now I didn't test it) I added a newpage.php in my site and forgot to add it in my array.</p>

<p>But my script instead of displaying my error.php it opened the newpage.php.</p>

<p>Where did I go wrong?</p>

<p>Thank you</p>
