I've searched for a day to find a solution for this,But no luck yet,
I have a function called : online()
this function is inside a file called client.php
which is located in root/dir/includes/client.php:
In client.php:
// 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") {
?>
<div id="online">
<?
} else {
?><div id="offline"> <?
}
echo 'client.php is included';
}
}
?>
About client.php:
first it establishes a database connection, then checks if a user is available, if yes : $available = "true";
else:
$available = "false";
Then I include client.php
in index.php
(located in root), So i Have:
in index.php:
$path = "dir/";
include $path . "includes/client.php";
So far so good, everything works,
The problem is...
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 client.php
:
include "../dir/includes/client.php";
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 $available = null
while it is expected to be "false"
as it is defined in client.php
The confusing thing is that, when I echo $available inside my wordpress header I can get the value, but when I echo it inside client.php
it is null again, so if I echo both in wordpress header and client.php
, when I open my wordpress page, I can see the one I included in header, and the other one inside client.php
is null.
Any help would be much appreciated.