Jump to content
php.lv forumi

php/ipb script


mamma*

Recommended Posts

vari lūdzu iemest aci? kkas neiet :(

ar sarkano krāsu atzīmēju visas vietas kur kautko mainiju!

 

<?

/*

* Marcis Kalnins

* [email protected]

*/

 

/*

### Usage:

include('class_ipb_online.php'); // include class to your script

$online = new ipb_online; // step 1 - start the class

# if you have database connection defined, continue to step 7

$online->db_host='localhost'; // step 2 - set the host of database, default is locahost

$online->db_user='user'; // step 3 - set the username of database user

$online->db_pass='pass'; // step 4 - set the password of database user

$online->db_name='datubaze'; // step 5 - set the name of database

$online->db(); // step 6 - create database connection

$error=false; // optional parameter to handle errors

if($online->create_cache('ibf_')){ // step 7 - give table prefix to function and get all online users from database

if($all=$online->get_all()){ // getting numbers of all users online and members online

echo '

Online: '.$all->total.'<br />

Guests: '.$all->guests.'<br />

Members: '.$all->members.'

';

if($members=$online->get_members('/forum/?showuser=',', ')){ // get all members online, give user url template and delimiter to function ', ' or '<br />' or anything you like :)

echo $members;

}else{

$error=true;

}

}else{

$error=true;

}

}else{

$error=true;

}

if($error==true){

echo 'We have no users online right now :(';

}

*/

 

class ipb_online {

var $db_host='localhost';

var $db_user;

var $db_pass;

var $db_name;

private $data;

 

function db(){

@mysql_connect($this->db_host,$this->db_user,$this->db_pass)or die(mysql_error());

@mysql_select_db($this->db_name)or die(mysql_error());

}

 

function create_cache($prefix=''){

$sql="SELECT member_name, member_id, member_group FROM `".$prefix."sessions` ORDER BY running_time DESC";

$res=mysql_query($sql);

if(@mysql_num_rows($res)<1){

return false;

}

while($row=mysql_fetch_assoc($res)){

$this->data[]=(object)$row;

}

return true;

}

 

function get_all(){

if(empty($this->data) || !is_array($this->data)){

return false;

}

$total=$members=$guests=0;

foreach($this->data as $value){

++$total;

if(!empty($value->member_id)){

++$members;

}else{

++$guests;

}

}

return (object)array('total'=>$total,'members'=>$members,'guests'=>$guests);

}

 

function get_members($url='?showuser=',$glue=', '){

if(empty($this->data) || !is_array($this->data)){

return false;

}

$out=array();

foreach($this->data as $value){

if(empty($value->member_id)){

continue;

}

$out[]='<a href="'.$url.intval($value->member_id).'" class="group_'.$value->member_group.'">'.$value->member_name.'</a>';

}

return implode($glue,$out);

}

}

?>

Link to comment
Share on other sites

Pat īsti nezinu, ko Tev atbildēt, ja Tu nezini kas ir komentārs kodā.

 

Pareizā pieeja būtu šāda:

<?
include('class_ipb_online.php');
$online = new ipb_online;
$online->db_host='localhost';
$online->db_user='username';
$online->db_pass='password';
$online->db_name='forum';
$online->db();
$error=false;
if($online->create_cache('ibf_')){
 if($all=$online->get_all()){
echo '
Online: '.$all->total.'<br />
Guests: '.$all->guests.'<br />
Members: '.$all->members.'
';
if($members=$online->get_members('/forum/?showuser=',', ')){
  echo $members;
}else{
  $error=true;
}
 }else{
$error=true;
 }
}else{
 $error=true;
}
if($error==true){
 echo 'We have no users online right now :(';
}
?>

Link to comment
Share on other sites

<?php
require_once 'inc/functions.php';
head();


//--- useri
$ipbwi->DB->query('SELECT id, members_display_name FROM '.SQL_PREFIX.'members WHERE last_activity >= '.intval((time() - 900)).' GROUP BY id');
echo "LIETOTĀJI (".$ipbwi->DB->get_num_rows().") <br />\n";
while($users = $ipbwi->DB->fetch_object()) {
echo "<a href='member.php?uid=".$users->id."' title='Apskatīt ".$users->members_display_name." profilu'>".$users->members_display_name."</a><br />\n";
}
//--- useri


//--- guesti
$ipbwi->DB->query('SELECT ip_address FROM '.SQL_PREFIX.'sessions WHERE member_id = 0 AND running_time >= '.intval((time() - 900)).' GROUP BY id');
echo "<br />CIEMIŅI (".$ipbwi->DB->get_num_rows().") <br />\n";
while($guests = $ipbwi->DB->fetch_object()) {
echo $guests->ip_address."<br />\n";
}
//--- guesti

$ipbwi->DB->close_db();


foot();
?>

 

nedaudz pielabot un strādās, ja nesanāk, lieto iepriekšminēto klasi ;)

Edited by rausis
Link to comment
Share on other sites

//--- useri
$res = mysql_query('SELECT id, members_display_name FROM ibf_members WHERE last_activity >= '.intval((time() - 900)).' GROUP BY id') or die(mysql_error());
echo "LIETOTĀJI (".mysql_num_rows($res).") <br />\n";
while($users = mysql_fetch_object($res)) {
echo "<a href='member.php?uid=".$users->id."' title='Apskatīt ".$users->members_display_name." profilu'>".$users->members_display_name."</a><br />\n";
}
//--- useri


//--- guesti
$res1 = mysql_query('SELECT ip_address FROM ibf_sessions WHERE member_id = 0 AND running_time >= '.intval((time() - 900)).' GROUP BY id') or die(mysql_error());
echo "<br />CIEMIŅI (".mysql_num_rows($res1).") <br />\n";
while($guests = mysql_fetch_object($res1)) {
echo $guests->ip_address."<br />\n";
}
//--- guesti

Link to comment
Share on other sites

Mārci ES pieliku klāt šo

 

header("Content-Type: text/html; charset=utf-8");
ini_set("display_errors","on");
error_reporting(E_ALL);

 

man parādījās ieejot manalapa.lv/xxx.php

 

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 4864 bytes) in /home/vol1/byethost11.com/b11_2802944/htdocs/class_ipb_online.php on line 2

 

 

 

a Rausis iemetu tavu script rekur =ar neiet :(

 

 

Problēma risināta viss strādā :)

Edited by mamma*
Link to comment
Share on other sites

×
×
  • Create New...