Register for your free account! | Forgot your password?

Go Back   elitepvpers > Other Online Games > Browsergames > DarkOrbit
You last visited: Today at 17:16

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Registered Counter [Private Server]

Discussion on Registered Counter [Private Server] within the DarkOrbit forum part of the Browsergames category.

Reply
 
Old   #1
 
darkorbitplayer1118's Avatar
 
elite*gold: 0
Join Date: Jun 2012
Posts: 350
Received Thanks: 247
Registered Counter [Private Server]

Hello epvpers! Today I present to you the Registered Counter v.1. All the information is presented below.


Registered Counter Code:
PHP Code:
<?php 
// [MySQL] Config
$host "localhost";
$username "root";
$password "";       // Leave blank if no password.
$database "";       // Your Private Server Database.
$table "users";

// Connect to mysql.
mysql_connect("$host","$username","$password") or die (mysql_error());
mysql_select_db("$database") or die (mysql_error());

// Database fuctions.
$usercount mysql_query("SELECT * FROM $table") or die (mysql_error());
$count mysql_num_rows($usercount);

echo 
"Registered:".$count;

// Created by darkorbitplayer1118
?>
* Make sure to type your database name and your password (leave blank if you have no password).

--------------------------------------------------
Want it in a php file instead?

Download link below.

DownloadVirustotal 
 
--------------------------------------------------
Instructions:

File Location:


Code Location (to place new code):


New Code (same place were old code was at):


Registration Page:

--------------------------------------------------
There you go works 100%
Have Fun!
darkorbitplayer1118 is offline  
Thanks
6 Users
Old 11/24/2013, 22:15   #2


 
Requi's Avatar
 
elite*gold: 3570
The Black Market: 244/0/0
Join Date: Dec 2012
Posts: 13,044
Received Thanks: 8,252
Doesn't ICON8 already have it?
Sky Universe as example.
Requi is offline  
Old 11/24/2013, 22:21   #3
 
darkorbitplayer1118's Avatar
 
elite*gold: 0
Join Date: Jun 2012
Posts: 350
Received Thanks: 247
Quote:
Originally Posted by Requi View Post
Doesn't ICON8 already have it?
as example.
Hmm i guess this code will be used for Azure and Aroura I guess. :P
darkorbitplayer1118 is offline  
Old 11/24/2013, 22:21   #4
 
UND3RW0RLD's Avatar
 
elite*gold: 1
Join Date: Jun 2011
Posts: 1,464
Received Thanks: 1,065
Proper version:

Put this in your backend:
PHP Code:
function usercount()
{
    
$usercount mysql_query("SELECT COUNT(*) FROM users") or die(mysql_error());

    echo 
"Registered:".mysql_result($usercount,0); 

and now you can use this function on various places of your website.

+ much faster
+ execution time does not depend on how big the db is
+ reusable
UND3RW0RLD is offline  
Thanks
3 Users
Old 11/24/2013, 22:25   #5
 
darkorbitplayer1118's Avatar
 
elite*gold: 0
Join Date: Jun 2012
Posts: 350
Received Thanks: 247
Quote:
Originally Posted by ǝnd1ǝss-ɯonǝʎ View Post
Proper version:

Put this in your backend:
PHP Code:
function usercount()
{
    
$usercount mysql_query("SELECT COUNT(*) FROM users") or die(mysql_error());

    echo 
"Registered:".$usercount

and now you can use this function on various places of your website.

+ much faster
+ execution time does not depend on how big the db is
+ reusable
Thanks for the advice but all I need to do is put an include function and put the mysql configuration in a separate file to fix the problem to be usable all over the website. Thank you anyways.

EDIT: Tested your code and it seems to not work for me. Does it need the Mysql config?
darkorbitplayer1118 is offline  
Old 11/25/2013, 10:43   #6
 
UND3RW0RLD's Avatar
 
elite*gold: 1
Join Date: Jun 2011
Posts: 1,464
Received Thanks: 1,065
To get it work you need a clearly structurated webkit.

$root/backend/secrets.php <-- Put the SQL-connection here
$root/backend/globalfunc.php <-- include "secrets" here and put the new function in here

$root/index.php <-- include globalfunc.php here and just execute the new function with
"usercount()"
UND3RW0RLD is offline  
Old 11/25/2013, 15:50   #7

 
Luffa's Avatar
 
elite*gold: 61
Join Date: Oct 2010
Posts: 1,188
Received Thanks: 2,403
Quote:
Originally Posted by ǝnd1ǝss-ɯonǝʎ View Post
Proper version:

Put this in your backend:
PHP Code:
function usercount()
{
    
$usercount mysql_query("SELECT COUNT(*) FROM users") or die(mysql_error());

    echo 
"Registered:".mysql_result($usercount,0); 

and now you can use this function on various places of your website.

+ much faster
+ execution time does not depend on how big the db is
+ reusable
It is a lot faster to use functions.
And if you even build-ed it into one of the existing class files, then you would save space.
And reusable when you have required it in an init file, so you would just need to use:
PHP Code:
$userb->playerCount(); 
Or if it is in same class script:
PHP Code:
self::playerCount(); 
Here is my examples of what you could do.
And it is also reusable, and uses pdo.

Example from my server-config
PHP Code:
## SQL Server Data
/*
$Config['MySQL'] = [
    'host' => 'localhost',
    'user' => 'root',
    'pass' => '',
    'dbname' => 'darkorbit'
];
*/
$Config = new stdClass();
$Config->MySQL = new stdClass();
$Config->MySQL->host "localhost";
$Config->MySQL->user "root";
$Config->MySQL->pass "";
$Config->MySQL->dbname "darkorbit"

define"DB_DSN""mysql:host=".$Config->MySQL->host.";dbname=".$Config->MySQL->dbname.""); //this constant will be use as our connectionstring/dsn
define"DB_USERNAME"$Config->MySQL->user ); //username of the database
define"DB_PASSWORD"$Config->MySQL->pass ); //password of the database 
Example class code returning the total number of the table: Class.Userbase.php
PHP Code:
class Userbase{
    private 
$con;
    
    public function 
__construct() {
        
$this->con = new PDO(DB_DSNDB_USERNAMEDB_PASSWORD);
        
$this->con->setAttribute(PDO::ATTR_ERRMODEPDO::ERRMODE_EXCEPTION);
        
    }

 public function 
playerCount(){
         
$query $this->con->prepare("SELECT COUNT(*) FROM tablename");
            if (
$query->execute()) {
                    
$count $query->rowCount();
               return 
$count
            
}
    }


This should actually work with azure->boxxy/madatek version.

And remember to edit the init.php
PHP Code:
require_once 'Class.Userbase.php';
$userb= new Userbase(); 
Then this on the front page should actually be enough.
PHP Code:
print_r($userb->playerCount()); 
I love PDO *-*

Best Regards RQ
Luffa is offline  
Thanks
1 User
Reply




All times are GMT +1. The time now is 17:17.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.