The following warnings occurred:
Warning [2] Use of undefined constant SAPI_NAME - assumed 'SAPI_NAME' (this will throw an Error in a future version of PHP) - Line: 3388 - File: inc/functions.php PHP 7.4.33-nmm6 (Linux)
File Line Function
/inc/functions.php 3388 errorHandler->error
/showthread.php 116 build_archive_link
Warning [2] Use of undefined constant IN_ARCHIVE - assumed 'IN_ARCHIVE' (this will throw an Error in a future version of PHP) - Line: 3331 - File: inc/functions.php PHP 7.4.33-nmm6 (Linux)
File Line Function
/inc/functions.php 3331 errorHandler->error
/inc/functions.php 3324 build_forum_breadcrumb
/showthread.php 195 build_forum_breadcrumb
Warning [2] Use of undefined constant IN_ARCHIVE - assumed 'IN_ARCHIVE' (this will throw an Error in a future version of PHP) - Line: 3331 - File: inc/functions.php PHP 7.4.33-nmm6 (Linux)
File Line Function
/inc/functions.php 3331 errorHandler->error
/showthread.php 195 build_forum_breadcrumb
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 786 - File: showthread.php PHP 7.4.33-nmm6 (Linux)
File Line Function
/showthread.php 786 errorHandler->error






Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[TUTORIAL] Sphere web status
Author Message
Kanibal
Master
**

Posts: 255
Likes Given: 6
Likes Received: 30 in 28 posts
Joined: Jun 2012
Reputation: 0



Post: #1
[TUTORIAL] Sphere web status
This is a quick and simple tutorial how to make your own sphere web status using Apache, MySQl and PHP.

First of we need is to download software.
1) Apache http server
2) PHP (Thread Safe)
3) MySQL server

Apache:
1) Unpack zip archive to your C:\ drive.
2) Go to C:\Apache24\conf and open httpd.conf
3) Now we need to configure some options here:
Paste
Code:
LoadModule php5_module "C:/php/php7apache2_4.dll"
PHPIniDir "C:/php"
after "LoadModule" section.

Find and uncomment line
Code:
#ServerName www.example.com:80
Change
Code:
www.example.com:80
to
Code:
localhost:80
Find
Code:
DocumentRoot "c:/Apache2/htdocs"
and change it to "c:/web". Than create empty folder web on a C:\ drive

Find block
Code:
<Directory />
    AllowOverride none
    Require all denied
</Directory>
and change it to
Code:
<Directory />
   Options Includes Indexes FollowSymLinks
   AllowOverride All
   Allow from all
</Directory>
Find and comment or remove block starts with <Directory "c:/Apache24/htdocs">

Find block
Code:
<IfModule dir_module>
   DirectoryIndex index.html
</IfModule>
and change it to
Code:
<IfModule dir_module>
   DirectoryIndex index.html index.htm index.shtml index.php
</IfModule>

Now find
Code:
ErrorLog "logs/error.log"
and change it to
Code:
ErrorLog "C:/web/error.log"
Also find
Code:
CustomLog "logs/access.log" common
and change it to
Code:
CustomLog "C:/web/access.log" common

Find block <IfModule mime_module> and add this to the end
Code:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

Finally find and uncomment this lines
Code:
Include conf/extra/httpd-mpm.conf
Include conf/extra/httpd-autoindex.conf
Include conf/extra/httpd-vhosts.conf
Include conf/extra/httpd-manual.conf
Include conf/extra/httpd-default.conf

Now open C:\Apache24\conf\extra\httpd-vhosts.conf, delete all content from it and type there
Code:
NameVirtualHost *:80

<VirtualHost *:80>
   DocumentRoot "C:/web/localhost/www"
   ServerName localhost
   ErrorLog "C:/web/localhost/error.log"
   CustomLog "C:/web/localhost/access.log" common
</VirtualHost>

Create directories "C:\web\localhost" and "C:\web\localhost\www"

Open command line as administrator type there "C:\Apache24\bin\httpd.exe -k install" and press enter. This will install Apache as service.

PHP:
1) Unpack zip archive to your C:\ drive. It should be C:\php
2) Go to C:\php, find file php.ini-development and rename it to php.ini

Uncomment
Code:
;include_path = ".;c:\php\includes"
Change
Code:
extension_dir = "./"
to
Code:
extension_dir = "C:/php/ext"
Find and uncomment next lines
Code:
extension=php_mbstring.dll
extension=php_mysqli.dll
Find, uncomment and change
Code:
;date.timezone =
to your timezone http://php.net/manual/en/timezones.php

MySQL:
Download and install MySQL server.

Go to installation path and open my.ini file.

In [mysql] section find
Code:
default-character-set
and change it to
Code:
default-character-set=utf8

In [mysqld] section find
Code:
character-set-server
and change it to
Code:
character-set-server=utf8

then find
Code:
default-storage-engine=INNODB
and change it to
Code:
default-storage-engine=MyISAM

also comment this line
Code:
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

PHPMyAdmin
Download "phpMyAdmin-4.6.5.2-all-languages.7z" from https://www.phpmyadmin.net/downloads/
Unpack zip archive to "C:\web\localhost\www" and rename "phpMyAdmin-4.6.5.2-all-languages" to "phpmyadmin".

Then go to "C:\web\localhost\www\phpmyadmin" and create empty file "config.inc.php" with this content
Code:
<?php
  $i = 0;
  $i++;
  $cfg['Servers'][$i]['host'] = 'localhost';
  $cfg['Servers'][$i]['extension'] = 'mysqli';
  $cfg['Servers'][$i]['connect_type'] = 'tcp';
  $cfg['Servers'][$i]['compress'] = false;
  $cfg['Servers'][$i]['auth_type'] = 'config';
  $cfg['Servers'][$i]['user'] = 'root'; // MySQL user
  $cfg['Servers'][$i]['password'] = 'pass'; // MySQL user password
?>

Sphere:
Open Sphere.ini uncomment and change this lines
Code:
// MySql configuration.
MYSQL=1
MySqlHost=127.0.0.1
MySqlUser=root
MySqlPassword=yourpassword
MySqlDatabase=sphere
Find TimerCall=0 and change it to a non zero value

Launch Apache and MySQL service, then go to http://localhost/phpmyadmin, log in with your user/pass and create database "sphere"

Then go to SQL commands and paste this code
Code:
CREATE TABLE IF NOT EXISTS `players_online` (
`uid` int(11) NOT NULL,
`name` varchar(50) NOT NULL,
`karma` int(5) NOT NULL,
`fame` int(5) NOT NULL,
`skilltotal` varchar(7) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

Now open sphere_serv_triggers.scp, find [FUNCTION f_onserver_timer] (add if not exists) and paste this lines
Code:
if (<db.connected>==0)
  db.connect
  db.query "SET NAMES utf8"
  db.query "SET CHARACTER SET utf8"
  db.query "SET character_set_client='utf8'"
  db.query "SET character_set_connection='utf8'"
  db.query "SET character_set_results='utf8'"
  return 0
endif

db.execute "TRUNCATE TABLE players_online"

serv.allclients f_update_player_status

Create in sme.scp function
Code:
[FUNCTION f_update_player_status]
if (<db.connected>==0)
  db.connect
  db.query "SET NAMES utf8"
  db.query "SET CHARACTER SET utf8"
  db.query "SET character_set_client='utf8'"
  db.query "SET character_set_connection='utf8'"
  db.query "SET character_set_results='utf8'"
  return 0
endif

db.execute "INSERT INTO players_online VALUES(<duid>, '<name>', <karma>, <fame>, '<skilltotal>')"

Now go to "C:\web\localhost\www" and create file status.php with this content
Code:
<?php
$link = mysqli_connect("127.0.0.1", "root", "my_password", "sphere"); //change my_password to your password

if (!$link) {
    echo "Error: Unable to connect to MySQL." . PHP_EOL;
    echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
    echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
    exit;
}

echo <<<HEADER
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title>SPHERE :: STATUS</title>
<style>
#status{
  margin; 0 auto;
  width 50%;
  height: auto;
  border-collapse: collapse;
}

#status th{
  border: 1px solid black;
  font-weight: bold;
}

#status td{
  border: 1px solid black;
}
</style>
</head>

<body>
<table id="status">
<tr><th>Name</th><th>Karma</th><th>Fame</th><th>Skill Total</th></tr>
HEADER;

$result = mysqli_query($link, "SELECT * FROM players_online");
while ($row = mysqli_fetch_assoc($result)) {
  echo '<tr><td>'.$row["name"].'</td><td>'.$row["karma"].'</td><td>'.$row["fame"].'</td><td>'.$row["skilltotal"].'</td></tr>';
}

echo <<<FOOTER
</table>
</body>
</html>
FOOTER;

mysqli_free_result($result);
mysqli_close($link);
?>


Grandmaster Localhost Admin
(This post was last modified: 11-15-2020 10:12 AM by Kanibal.)
12-09-2016 10:09 PM
Visit this user's website Find all posts by this user Like Post Quote this message in a reply
Post Reply 


Messages In This Thread
[TUTORIAL] Sphere web status - Kanibal - 12-09-2016 10:09 PM
RE: [TUTORIAL] Sphere web status - Kanibal - 12-27-2016, 09:24 AM
RE: [TUTORIAL] Sphere web status - Kanibal - 12-27-2016, 11:04 PM
RE: [TUTORIAL] Sphere web status - anexity - 04-28-2017, 08:00 AM
RE: [TUTORIAL] Sphere web status - Kanibal - 05-11-2017, 07:23 PM
RE: [TUTORIAL] Sphere web status - golfin - 10-06-2018, 10:51 PM
RE: [TUTORIAL] Sphere web status - Kanibal - 10-20-2018, 08:47 AM
RE: [TUTORIAL] Sphere web status - golfin - 10-21-2018, 01:22 PM

Forum Jump:


User(s) browsing this thread: 1 Guest(s)