Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You have run into a little problem with your variable scoping.</p> <p>Any variables outside a function in PHP is not accessible inside. There are multiple ways to overcome this.</p> <p>You could either declare <code>$bannedIPs</code> inside your function as such:</p> <pre><code>function ipban() { $bannedIPs = array('127.0.0.1','72.189.218.85'); if (in_array($_SERVER['REMOTE_ADDR'], $bannedIPs)) { echo 'test'; } } </code></pre> <p>Tell your function to access <code>$bannedIPs</code> outside the function using the <strong><code>global</code></strong> keyword:</p> <pre><code>$bannedIPs = array('127.0.0.1','72.189.218.85'); function ipban() { global $bannedIPs; if (in_array($_SERVER['REMOTE_ADDR'], $bannedIPs)) { echo 'test'; } } </code></pre> <p>Or, use the <code>$GLOBALS</code> super global:</p> <pre><code>$bannedIPs = array('127.0.0.1','72.189.218.85'); function ipban() { if (in_array($_SERVER['REMOTE_ADDR'], $GLOBALS['bannedIPs'])) { echo 'test'; } } </code></pre> <p>I recommend you read the manual page on Variable scope:</p> <p><a href="http://www.php.net/manual/en/language.variables.scope.php" rel="nofollow noreferrer">PHP: Variable Scope</a></p> <hr> <p><strong>If it's still not working, you have another problem in your code. In which case, you might want to consider using a <code>var_dump()</code> to check what datatype is <code>$bannedIPs</code> before down voting us all.</strong></p> <pre><code>function ipban() { global $bannedIPs; var_dump($bannedIPs); } </code></pre>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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