Note that there are some explanatory texts on larger screens.

plurals
  1. POphp global variable doesn't work inside included file
    primarykey
    data
    text
    <p>I've searched for a day to find a solution for this,But no luck yet, I have a function called : <code>online()</code> this function is inside a file called <code>client.php</code> which is located in root/dir/includes/client.php:</p> <h3>In client.php:</h3> <pre><code>// db connection include "base.php"; // check if availabe $available = "false"; $check = mysql_query("SELECT available FROM users "); while ($row=mysql_fetch_array($check)) { if($row['available'] == "yes") { $available = "true"; } } // get config $fetch = mysql_query("SELECT * FROM config "); $config = mysql_fetch_array($fetch); // functions function online() { // globals global $available,$config,$path; // build box if($available == "true") { ?&gt; &lt;div id="online"&gt; &lt;? } else { ?&gt;&lt;div id="offline"&gt; &lt;? } echo 'client.php is included'; } } ?&gt; </code></pre> <h3>About client.php:</h3> <p>first it establishes a database connection, then checks if a user is available, if yes : <code>$available = "true";</code> else: <code>$available = "false";</code></p> <p>Then I include <code>client.php</code> in <code>index.php</code> (located in root), So i Have:</p> <h3>in index.php:</h3> <pre><code>$path = "dir/"; include $path . "includes/client.php"; </code></pre> <p>So far so good, everything works, </p> <h2>The problem is...</h2> <p>I need to use this function in other pages in sub directories too, to be more specific, I'm trying to add this function to my wordpress website which is located in: root/wp in my wordpress header I include <code>client.php</code> :</p> <pre><code>include "../dir/includes/client.php"; </code></pre> <p>And I get the output , So i'm sure it is included, But, none of my global variables work when I open my wordpress (root/wp) resulting in <code>$available = null</code> while it is expected to be <code>"false"</code> as it is defined in <code>client.php</code></p> <p>The confusing thing is that, when I echo $available inside my wordpress header I can get the value, but when I echo it inside <code>client.php</code> it is null again, so if I echo both in wordpress header and <code>client.php</code> , when I open my wordpress page, I can see the one I included in header, and the other one inside <code>client.php</code> is null.</p> <p>Any help would be much appreciated.</p>
    singulars
    1. This table or related slice is empty.
    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