Nadanie strefy czasowej

Założony przez  Szogi1910.

Witam
Posiadam pewien skrypt, który pobiera dane z serwera gry następnie zapisuje je do bazy mysql i wyświetla na stronie www lecz mam jeden mały problem wszelkie dodane rekordy mają źle pobierane dane dla kolumn Pierwsze Wejście oraz Ostatnio Online mianowicie pobrane rekordy pokazują 2godziny do tyłu, cały skrypt można znaleźć pod linkiem http://www.project-games.eu/logi/time/dd2/?p=1

Teraz moje pytanie czy do owego skryptu można dodać kod php, który będzie regulował czas czyli dodawał te 2godziny

plik konfiguracyjny
<?php
/**
 * Plik konfiguracyjny
 */
 
// ------------------------
// Host bazy danych
// ------------------------
$CONFIG['db_host']  = '127.0.0.1';

// ------------------------
// Użytkownik bazy danych
// ------------------------
$CONFIG['db_user']  = ';

// ------------------------
// Hasło użytkownika bazy danych
// ------------------------
$CONFIG['
db_pass']  = '';

// ------------------------
// Nazwa bazy danych
// ------------------------
$CONFIG['
db_name']  = '';

// ------------------------
// Tabela czasu xD
// ------------------------
$CONFIG['
db_table'] = 'players_time_dd2';


// ---------------------------------------
// Tego niżej nie ruszać xD
// ---------------------------------------
error_reporting(0);

try {
    $pdo = new PDO("mysql:host={$CONFIG['
db_host']};dbname={$CONFIG['db_name']}", $CONFIG['db_user'], $CONFIG['db_pass']);
}

catch(PDOException $exception) {
    print "<h3>Błąd mysql</h3>";
    print $exception->getMessage();
    exit;
}

class Czas {
    public $db = null;
    public $config = array();
    
    public function __construct($pdo_handle, $config) {
        $this->db      = $pdo_handle;
        $this->config  = $config;
    }
    
    public function getRecord($start = 0, $count = 100, $order = array(), $search) {
        $start = intval($start);
        $count = intval($count);
        
        $sql = "SELECT * FROM `{$this->config['
db_table']}` ";
        
        if(isset($search['
nick'])) {
            $search['
nick'] = addslashes($search['nick']);
            $sql .= "where `nick` LIKE '
%{$search['nick']}%' ";
        }
        
        if(isset($order['
type']) && isset($order['by'])) {
            $by    = addslashes($order['
by']);
            $type  = addslashes($order['
type']);
            
            
            $sql .= "order by `{$by}` {$type} ";
        }
        
        $sql .= "LIMIT {$start}, {$count} ";
    
        $res = $this->db->query($sql);
        return $res->fetchAll();
    }
}
$mq = new Czas($pdo, $CONFIG); 

index
<?php
require 'config.php';
?>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="target-densitydpi=device-dpi, width=device-width, initial-scale=1.0, maximum-scale=1">
    <!-- Metro UI -->
    <link href="css/modern.css" rel="stylesheet">
    <link href="css/site.css" rel="stylesheet" type="text/css">
    <!--  Metro UI -->
    <title>Czas Online</title>    
</head>
<body class="metrouicss">
    <div class="page">
            <div class="nav-bar">
                <div class="nav-bar-inner padding10">
                    <span class="pull-menu"></span>            
                    <a href="/">
                        <span class="element brand">
                            <img class="place-left" src="images/logo32.png" style="height: 20px"/>
                            Czas Online
                        </span>
                    </a>            
                    <div class="divider"></div>
                    <ul class="menu">
                        <li><a href="/">Strona Główna</a></li>
                                            </ul>
                </div>
            </div> 
            <div class="page-header">
                <div class="page-header-content">
                    <h1>Czas Online</h1>
                </div>
            </div>
            <div class="page-region">
                <div class="page-region-content">
                            <h2>Szukaj</h2>
                                    <form method="post" action="">
                                        <div class="input-control text span4">
                                            <input type="text" value="<?php echo isset($_POST['nick']) ? $_POST['nick'] : '' ?>" name="nick" autofocus />
                                            <button class="btn-search"/>
                                        </div>
                                    </form>
                            <table class="bordered" style="text-align: center;">
                                <thead>
                                    <tr>
                                        <?php $sort = (isset($_GET['sort']) && $_GET['sort'] == 'asc') ? 'desc' 'asc'?>
                                        <th><a href="?sort=<?php echo $sort ?>&by=nick">Nick</a></th>
                                        <th><a href="?sort=<?php echo $sort ?>&by=steamid">SteamID</a></th>
                                        <th><a href="?sort=<?php echo $sort ?>&by=time">Czas Online</a></th>
                                        <th><a href="?sort=<?php echo $sort ?>&by=first">Pierwsze Wejście</a></th>
                                        <th><a href="?sort=<?php echo $sort ?>&by=last">Ostatnio Online</a></th>
                                    </tr>
                                </thead>
                                <tbody>
                                <?php
                                    
// -------------------------
                                    // Stronnicowanie
                                    // -------------------------
                                    
$curr_page = (isset($_GET['p']) && $_GET['p'] > 1) ? $_GET['p'] : 0
                                    
$start 0;
                                    if(
$curr_page 1) {
                                        
$start $curr_page 20 20;
                                    }
                                
                                    
// -------------------
                                    // Sortowanie
                                    // -------------------
                                    
$order_by   'time';
                                    
$order_type 'DESC';
                                    if(isset(
$_GET['sort'])) {
                                        
$order_type strtoupper($_GET['sort']) == 'ASC' 'ASC' 'DESC';
                                    }
                                    if(isset(
$_GET['by'])) {
                                        
$order_by   $_GET['by'];
                                    }
                                
                                    
// -------------------------------
                                    // Pobieranie rekordów dla danego kryterium
                                    // -------------------------------
                                    
$record $mq -> getRecord($start20, array(
                                        
'by'    => $order_by,
                                        
'type'  => $order_type
                                    
), $_POST);
                                    
                                    if(
count($record)) {
                                        for(
$i=0$c=count($record); $i<$c$i++) {
                                            
$data $record[$i];
                                            
                                            echo 
'<tr' .( $data'type' ] ? ' class="selected-row" ' ''). '>';
                                            echo 
'<td>' htmlspecialchars($data['nick']) . '</td>';
                                            echo 
'<td>' $data['steamid'] . '</td>';
                                            echo 
'<td>' gmdate("H:i:s"$data['time']) . '</td>';
                                            echo 
'<td>' gmdate("d.m.Y (H:i:s)"$data['first']) . '</td>';
                                            echo 
'<td>' gmdate("d.m.Y (H:i:s)"$data['last']) . '</td>';
                                             echo 
'</tr>';
                                        }
                                    }
                                    else {
                                        print 
"<tr class='error'><td colspan='5'>Brak wyników dla tego zapytania</td></tr>";
                                    }
                                
?>
                                </tbody>            
                            </table>
                                <br /><br />
                                <div class="pagination">
                                    <ul>
                                        <?php
                                        
// ---------------------------
                                        // Wyświetlanie stron
                                        // ---------------------------
                                        
$q $pdo -> query("SELECT COUNT(`id`) AS `records` FROM `{$CONFIG['db_table']}`");
                                        
$q $q -> fetch();
                                        
$records $q['records'];
                                        
                                        
$page ceil($records/20);
                                        
                                        for(
$i=0$i<$page$i++) {
                                            echo 
'<li class="' . ( ( $curr_page == $i ) ? 'active' '' ) . '"><a href="?p='.($i+1).'">' . ($i+1) . '</a></li>';
                                        }
                                        
?>
                                    </ul>
                                </div>
                                <br />
                               </div>
                        </div>          
                </div> 
    </div>     
</body>
</html> 
Może spróbuj ustawić strefę czasową dla serwera WWW lub pokaż co znajduję się w PHPMyAdmin w kolumnie "players_time_dd2".
Pomogłem?
Kliknij "Pomógł"
To nic nie kosztuje a dużo dla mnie znaczy.
   

Cały skrypt pobiera z innego serwera dane jak godzina i date
Widzię że skrypt przelicza czas na sekundy.

Więc musimy pokombinować i np. zrobić aby do wartości czasu dodawało 7200.

Rozumiem że używasz pluginu z amxx.pl?
Pomogłem?
Kliknij "Pomógł"
To nic nie kosztuje a dużo dla mnie znaczy.
No dokładnie, tylko plugin po stronie serwera gry ma dodane małe urozmaicenie acz kolwiek cała budowa opiera się na pluginie z amxx

Edit

Po niżej zamieszczam plugin po stornie serwera
#include < amxmodx >
#include < sqlx >
[ciach]
}

enum playerData {
    
SteamID33 ],
    
IP16 ],
    
Nick64 ],
    
Time
};

new 
HandlegSqlTuple;

new 
gPlayer33 ][ playerData ];

public 
SqlInit( ) {
    
gSqlTuple SQL_MakeDbTuplesqlConfig], sqlConfig], sqlConfig], sqlConfig] );
    
    if( 
gSqlTuple == Empty_Handle )
        
set_fail_state"Nie mozna utworzyc uchwytu do polaczenia" );
    
    new 
iErrszError32 ];
    new 
Handle:link SQL_ConnectgSqlTupleiErrszError31 );
    
    if( 
link == Empty_Handle ) {
        
log_amx"Error (%d): %s"iErrszError );
        
set_fail_state"Brak polaczenia z baza danych" );
    }
    
    new 
Handlequery;
    
query SQL_PrepareQuerylink"CREATE TABLE IF NOT EXISTS `players_time_dd2` (\
        `id` int(11) NOT NULL AUTO_INCREMENT,\
        `steamid` varchar(33) NOT NULL,\
        `nick` varchar(64) NOT NULL,\
        `ip` varchar(16) NOT NULL,\
        `first` int(16) NOT NULL,\
        `last` int(16) NOT NULL,\
        `time` int(16) NOT NULL,\
        `type` int(1) NOT NULL,\
        PRIMARY KEY (`id`),\
        UNIQUE KEY `authid` (`nick`)\
    )" 
);
    
    
SQL_Executequery );
    
SQL_FreeHandlequery );
    
SQL_FreeHandlelink );
}

public 
QueryfailstateHandle:queryerror[ ] ) {
    if( 
failstate != TQUERY_SUCCESS ) {
        
log_amx"SQL query error: %s"error );
        return;
    }
}

public 
plugin_init() {
    
register_plugin"Czas Online""2.1.0""byCZEK" );
    
    
set_task0.1"SqlInit" );
}

public 
client_connectid ) {
    
gPlayerid ][ Time ] = 0;
    
    
get_user_authididgPlayerid ][ SteamID ], 32 );
    
get_user_ipidgPlayerid ][ IP ], 15);
    
get_user_nameidgPlayerid ][ Nick ], 63 );
    
    
SQL_PrepareStringgPlayerid ][ Nick ], gPlayerid ][ Nick ], 63 );
}

[
ciach :D]

public 
client_disconnectid ) {
    if(
is_user_hltv(id) || is_user_bot(id))
        return 
PLUGIN_HANDLED;
        
    
gPlayerid ][ Time ] = get_user_timeid);
    
    
saveTimeid );
    
    
gPlayerid ][ Time ] = 0;
    
    return 
PLUGIN_CONTINUE;
}

stock SQL_PrepareString( const szQuery[], szOutPut[], size ) {
    
copyszOutPutsizeszQuery );
    
replace_allszOutPutsize"'""\'" );
    
replace_allszOutPutsize"`""\`" );    
    
replace_allszOutPutsize"\\""\\\\" );
    
replace_allszOutPutsize"^0""\0");
    
replace_allszOutPutsize"^n""\n");
    
replace_allszOutPutsize"^r""\r");
    
replace_allszOutPutsize"^x1a""\Z");    
}

stock saveTimeid ) {
    new     
query1024 ],
    
flags get_user_flagsid );
    
    
formatexquerycharsmaxquery ), "INSERT IGNORE INTO `players_time_dd2` ( `steamid`, `nick`, `ip`, `first`, `last`, `time`, `type` ) VALUES ( '%s', '%s', '%s', UNIX_TIMESTAMP(NOW()), UNIX_TIMESTAMP(NOW()), %d, %d ) ON DUPLICATE KEY UPDATE `time` = `time` + %d, `last` = UNIX_TIMESTAMP(NOW())",
    
gPlayerid ][ SteamID ], gPlayerid ][ Nick ], gPlayerid ][ IP ], gPlayerid ][ Time ], ( ( flags && !( flags ADMIN_USER ) ) ? ), gPlayerid ][ Time ]);
    
    if( 
gSqlTuple )
        
SQL_ThreadQuery (gSqlTuple"Query"query );
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1045\\ f0\\ fs16 \n\\ par }
*/ 
Nie masz możliwości zmiany strefy czasowej po stronie tego serwera co zapisuje błędną datę?
W tym problem że nie posiadam takiej możliwości aby zmienić datę, więc muszę to jakoś nadpisać poprzez owy skrypt
UNIX_TIMESTAMP(NOW()) 

Poczytaj o mktime() w PHP i przed formatex() w funkcji saveTime() w skrypcie po stronie serwera umieść zmienną, która przechowa ten mktime... Albo inne rozwiązanie, podczas odczytu danych z bazy, dodaj po prostu +2 do godzin.
Czy ktoś znalazł rozwiązanie?
Także posiadam ten skrypt i także mam ten sam problem ;/
Pomogłem?
Kliknij "Pomógł"
To nic nie kosztuje a dużo dla mnie znaczy.



Użytkownicy przeglądający ten wątek:

1 gości