1
xsell
How to Create Php Block?
  • 2009/3/7 10:54

  • xsell

  • Quite a regular

  • Posts: 245

  • Since: 2008/9/2 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.php

But 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); 
?>

2
zyspec
Re: How to Create Php Block?
  • 2009/3/7 14:20

  • zyspec

  • Module Developer

  • Posts: 1095

  • Since: 2004/9/21


xsell,

Don't include the '' in your block.

Did you try turning on PHP debug in Administration to see if it gives you any errors?

3
xsell
Re: How to Create Php Block?
  • 2009/3/7 21:58

  • xsell

  • Quite a regular

  • Posts: 245

  • Since: 2008/9/2 1


Hey ..

just embty block and some block even stopped working after do wht u said ..the right thing to do is to make a module and add the file as block .. but i dont want star now learn php .. hope some one can make it for me i can include the sql file it just two tabels.

4
trabis
Re: How to Create Php Block?
  • 2009/3/8 1:56

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


Maybe this module is useful for you:
http://www.xuups.com/modules/publisher/item.php?itemid=7

Membership has an online block that seems to do the same you want to do with that script.

5
xsell
Re: How to Create Php Block?
  • 2009/3/8 3:57

  • xsell

  • Quite a regular

  • Posts: 245

  • Since: 2008/9/2 1


thx trabis , i have used membership module before , it just the huge database that i have to install into XOOPS database wht made me uninstall it .. i use cron job back up script to back up my database and with membership module installed it makes the backup fails sometime .. the above file i use for online users is depand script i could use iframe code to include it block , but it didt look good ..

Login

Who's Online

332 user(s) are online (282 user(s) are browsing Support Forums)


Members: 0


Guests: 332


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits