1
Hello
I did My Homework and Searched how to Add Php Code as Block , but all my trys fail .. . the php code i have it works when i run it from my site as
http://www.sitename.com/file.phpBut if i add the content as block from the admin panel i get white page or nothing shown on the block ..
This php file is small script to Show online users , it need Database , but i have it Seprate from XOOPS MySQL , i dont want this script share my XOOPS database but i want it to run from XOOPS as block .. is there any way ..
Oh by the way i can run it if i use IFRAME code to add the block as Html but iframe look ugly ..
idid add the block as php file but it didt do and thing just nothing in the block ..
////////////////////////////////
//Database settings
$server = "localhost";
$db_user = "user";
$db_pass = "pass";
$database = "db";
$dbh = mysql_connect($server, $db_user, $db_pass);
// don't change settings below
$table = "useronline";
//Connect DB
mysql_connect($server, $db_user, $db_pass);
//Select DB
mysql_select_db($database, $dbh);
//Fetch Time
$timeoutseconds = 10;
$timestamp = time();
$timeout = $timestamp - $timeoutseconds;
//Delete User
mysql_db_query($database, "DELETE FROM $table WHERE ip='$_SERVER[REMOTE_ADDR]'") or die("Cannot connect to the database");
mysql_db_query($database, "DELETE FROM $table WHERE timestamp<$timeout") or die("Cannot connect to the database");
//Insert User
$ip = $_SERVER['REMOTE_ADDR'];
$insert = mysql_db_query($database, "INSERT INTO $table VALUES
('$timestamp','$ip','$PHP_SELF')") or die("Cannot connect to the database");
//Fetch Users Online
$result = mysql_db_query($database, "SELECT DISTINCT ip FROM $table WHERE file='$PHP_SELF'") or die("Failed!");
$users = mysql_num_rows($result);
// Compare IP's found in the database
while ($row = mysql_fetch_array($result)) {
$country_query = '
SELECT country2
FROM iptocountry
WHERE ipfrom < INET_ATON("'.$row['ip'].'")
ORDER BY ipfrom DESC
LIMIT 0,1';
//Set country code in array
$country_exec = mysql_query($country_query);
$ccode_array=mysql_fetch_array($country_exec);
$country_code=$ccode_array['country2'];
//Change to lowercase
$country_code = strtolower($country_code);
// Cut IP's
$line = substr("$row[ip]",0,5);
// Addind xx and
$showip = chunk_split($line,30,".xx.xx n");
echo "
n";
// spit out the results (ip.xx flag)
echo "$showip $country_code.png' border ='no'>n";
}
echo "
n";
echo "Online $users User(s)n";
// Close DB
mysql_close($dbh);
?>