bro,can u do for me
it always refresh to yourdomain/error.php
Code:
<?php
// THIS FILE IS MADE TO MAKE CUSTOMIZING MUCH EASIER. SIMPLY ENTER YOUR SERVER DETAILS HERE AND THEY WILL CHANGE ITSELF.
define('SVRNAME', 'Server name');// the name of your server
define('OWNER', 'Adam'); //server owner name
define('SVRIP', ''); //Your server's IP.
define('SVRSLOGAN', 'This is a free template dedicated to SA-MP communities.'); //Your server's slogan
require("samp_query.php");
$serverIP = "139.59.252.227"; // Add in your server IP. DO NOT ADD THE PORT HERE, ADD IT BELOW!
$serverPort = 7777; // Server Port.
?>
Code:
<?php
/*********************************************
*
* SA-MP Query Server Version 0.3
*
* This class provides you with an easy to use interface to query
* your SA-MP 0.2 servers. Usage is simple, but has changed a bit
* since the last version, so be sure to check out the examples
* that come along with this script. It is updated with some of
* the new SA-MP 0.2 query-techniques that can be used.
*
* Author: Peter Beverloo
* peter@dmx-network.com
* Ex SA-MP Developer
*
* Updated: Wouter van Eekelen
* wouter.van.eekelen@serverffs.com
* SA-MP Betatester
*********************************************/
class QueryServer
{
// Private variables used for the query-ing.
private $szServerIP;
private $iPort;
private $rSocketID;
private $bStatus;
// The __construct function gets called automatically
// by PHP once the class gets initialized.
function __construct( $szServerIP, $iPort )
{
$this->szServerIP = $this->VerifyAddress( $szServerIP );
$this->iPort = $iPort;
if (empty( $this->szServerIP ) || !is_numeric( $iPort )) {
throw new QueryServerException( 'Either the ip-address or the port isn\'t filled in correctly.' );
}
$this->rSocketID = @fsockopen( 'udp://' . $this->szServerIP, $iPort, $iErrorNo, $szErrorStr, 5 );
if (!$this->rSocketID) {
throw new QueryServerException( 'Cannot connect to the server: ' . $szErrorStr );
}
socket_set_timeout( $this->rSocketID, 0, 500000 );
$this->bStatus = true;
}
// The VerifyAddress function verifies the given hostname/
// IP address and returns the actual IP Address.
function VerifyAddress( $szServerIP )
{
if (ip2long( $szServerIP ) !== false &&
long2ip( ip2long( $szServerIP ) ) == $szServerIP ) {
return $szServerIP;
}
$szAddress = gethostbyname( $szServerIP );
if ($szAddress == $szServerIP) {
return "";
}
return $szAddress;
}
// The SendPacket function sends a packet to the server which
// requests information, based on the type of packet send.
function SendPacket( $cPacket )
{
$szPacket = 'SAMP';
$aIpChunks = explode( '.', $this->szServerIP );
foreach( $aIpChunks as $szChunk ) {
$szPacket .= chr( $szChunk );
}
$szPacket .= chr( $this->iPort & 0xFF );
$szPacket .= chr( $this->iPort >> 8 & 0xFF );
$szPacket .= $cPacket;
return fwrite( $this->rSocketID, $szPacket, strlen( $szPacket ) );
}
// The GetPacket() function returns a specific number of bytes
// read from the socket. This uses a special way of getting stuff.
function GetPacket( $iBytes )
{
$iResponse = fread( $this->rSocketID, $iBytes );
if ($iResponse === false) {
throw new QueryServerException( 'Connection to ' . $this->szServerIP . ' failed or has dropped.' );
}
$iLength = ord( $iResponse );
if ($iLength > 0)
return fread( $this->rSocketID, $iLength );
return "";
}
// After we're done, the connection needs to be closed using
// the Close() function. Otherwise stuff might go wrong.
function Close( )
{
if ($this->rSocketID !== false) {
fclose( $this->rSocketID );
}
}
// A little function that's needed to properly convert the
// four bytes we're recieving to integers to an actual PHP
// integer. ord() can't handle value's higher then 255.
function toInteger( $szData )
{
$iInteger = 0;
$iInteger += ( ord( @$szData[ 0 ] ) );
$iInteger += ( ord( @$szData[ 1 ] ) << 8 );
$iInteger += ( ord( @$szData[ 2 ] ) << 16 );
$iInteger += ( ord( @$szData[ 3 ] ) << 24 );
if( $iInteger >= 4294967294 )
$iInteger -= 4294967296;
return $iInteger;
}
// The GetInfo() function returns basic information about the
// server, like the hostname, number of players online etc.
function GetInfo( )
{
if ($this->SendPacket('i') === false) {
throw new QueryServerException( 'Connection to ' . $this->szServerIP . ' failed or has dropped.' );
}
$szFirstData = fread( $this->rSocketID, 4 );
if (empty( $szFirstData ) || $szFirstData != 'SAMP') {
throw new QueryServerException( 'The server at ' . $this->szServerIP . ' is not an SA-MP Server.' );
}
// Pop the first seven characters returned.
fread( $this->rSocketID, 7 );
return array (
'Password' => ord( fread( $this->rSocketID, 1 ) ),
'Players' => $this->toInteger( fread( $this->rSocketID, 2 ) ),
'MaxPlayers' => $this->toInteger( fread( $this->rSocketID, 2 ) ),
'Hostname' => $this->GetPacket( 4 ),
'Gamemode' => $this->GetPacket( 4 ),
'Map' => $this->GetPacket( 4 )
);
}
// The GetRules() function returns the rules which are set
// on the server, e.g. the gravity, version etcetera.
function GetRules( )
{
if ($this->SendPacket('r') === false) {
throw new QueryServerException( 'Connection to ' . $this->szServerIP . ' failed or has dropped.' );
}
// Pop the first 11 bytes from the response;
fread( $this->rSocketID, 11 );
$iRuleCount = ord( fread( $this->rSocketID, 2 ) );
$aReturnArray = array( );
for( $i = 0; $i < $iRuleCount; $i ++ ) {
$szRuleName = $this->GetPacket( 1 );
$aReturnArray[ $szRuleName ] = $this->GetPacket( 1 );
}
return $aReturnArray;
}
// The GetPlayers() function is pretty much simelar to the
// detailed function, but faster and contains less information.
function GetPlayers( )
{
if ($this->SendPacket('c') === false) {
throw new QueryServerException( 'Connection to ' . $this->szServerIP . ' failed or has dropped.' );
}
// Again, pop the first eleven bytes send;
fread( $this->rSocketID, 11 );
$iPlayerCount = ord( fread( $this->rSocketID, 2 ) );
$aReturnArray = array( );
for( $i = 0; $i < $iPlayerCount; $i ++ )
{
$aReturnArray[ ] = array (
'Nickname' => $this->GetPacket( 1 ),
'Score' => $this->toInteger( fread( $this->rSocketID, 4 ) )
);
}
return $aReturnArray;
}
// The GetDetailedPlayers() function returns the player list,
// but in a detailed form inclusing the score and the ping.
function GetDetailedPlayers( )
{
if ($this->SendPacket('d') === false) {
throw new QueryServerException( 'Connection to ' . $this->szServerIP . ' failed or has dropped.' );
}
// Skip the first 11 bytes of the response;
fread( $this->rSocketID, 11 );
$iPlayerCount = ord( fread( $this->rSocketID, 2 ) );
$aReturnArray = array( );
for( $i = 0; $i < $iPlayerCount; $i ++ ) {
$aReturnArray[ ] = array(
'PlayerID' => $this->toInteger( fread( $this->rSocketID, 1 ) ),
'Nickname' => $this->GetPacket( 1 ),
'Score' => $this->toInteger( fread( $this->rSocketID, 4 ) ),
'Ping' => $this->toInteger( fread( $this->rSocketID, 4 ) )
);
}
return $aReturnArray;
}
function RCON($rcon, $command)
{
echo 'Password '.$rcon.' with '.$command;
if ($this->SendPacket('x '.$rcon.' '.$command) === false) {
throw new QueryServerException( 'Connection to ' . $this->szServerIP . ' failed or has dropped.' );
}
// Pop the first 11 bytes from the response;
$aReturnArray = fread( $this->rSocketID, 11 );
echo fread( $this->rSocketID, 11 );
return $aReturnArray;
}
}
/*********************************************
*
* The QueryServerException is used to throw errors when querying
* a specific server. That way we force the user to use proper
* error-handling, and preferably even a try-/catch statement.
*
**********************************************/
class QueryServerException extends Exception
{
// The actual error message is stored in this variable.
private $szMessage;
// Again, the __construct function gets called as soon
// as the exception is being thrown, in here we copy the message.
function __construct( $szMessage )
{
$this->szMessage = $szMessage;
}
// In order to read the exception being thrown, we have
// a .NET-like toString() function, which returns the message.
function toString( )
{
return $this->szMessage;
}
}
?>
Code:
<?php
require("settings.php"); // everything must be set in that file (server IP, variables etc.)
try
{
$rQuery = new QueryServer( $serverIP, $serverPort );
$aInformation = $rQuery->GetInfo( );
$aServerRules = $rQuery->GetRules( );
$aBasicPlayer = $rQuery->GetPlayers( );
$aTotalPlayers = $rQuery->GetDetailedPlayers( );
$rQuery->Close( );
}
catch (QueryServerException $pError)
{
header("Location: http://yourdomain/error.php"); // Redirects to an error page if the server is offline. Change this according to your site domain name. You can customize the error page by opening 'error.php'
}
if(isset($aInformation) && is_array($aInformation)){
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?php echo SVRNAME; ?> - Server</title>
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="css/style.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#"><?php echo SVRNAME; ?></a>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<li><a href="#">Home (Coming Soon)</a></li>
<li class="active"><a href="demo.php">Server</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
<!-- BANNER START -->
<div class="banner-head">
<h1><?php echo SVRNAME; ?></h1>
<h3><?php echo SVRSLOGAN; ?></h3>
</div>
<!-- BANNER END -->
<!-- ABOUT START -->
<div class="page-section-grey-title">
<h1>Server Statistics</h1>
<h4>View all of our server statistics here!</h4>
</div>
<!-- ABOUT END -->
<!-- SERVER STATS START -->
<div class="page-section-server-stats">
<h2>Server Information:</h2>
<div class="table-responsive">
<table class="table table-striped table-bordered" style="width:700px;" align="center">
<tr>
<td><b>Hostname</b></td>
<td><?php echo htmlentities($aInformation['Hostname']); ?></td>
</tr>
<tr>
<td><b>Gamemode</b></td>
<td><?php echo htmlentities($aInformation['Gamemode']); ?></td>
</tr>
<tr>
<td><b>Players</b></td>
<td><?php echo $aInformation['Players']; ?> / <?php echo $aInformation['MaxPlayers']; ?></td>
</tr>
<tr>
<td><b>Map</b></td>
<td><?php echo htmlentities($aInformation['Map']); ?></td>
</tr>
<tr>
<td><b>Time</b></td>
<td><?php echo $aServerRules['worldtime']; ?></td>
</tr>
<tr>
<td><b>Version</b></td>
<td><?php echo $aServerRules['version']; ?></td>
</tr>
</table>
</div>
<!-- SERVER STATS END -->
<br/>
<!-- SERVER PLAYERS START -->
<h2>Online Players:</h2>
<?php
if(!is_array($aTotalPlayers) || count($aTotalPlayers) == 0){
echo '<br /><i>No players online!</i>';
} else {
?>
<table class="table table-striped table-bordered" style="width:700px;" align="center">
<tr>
<td><b>Player ID</b></td>
<td><b>Nickname</b></td>
<td><b>Score</b></td>
</tr>
<?php
foreach($aTotalPlayers AS $id => $value){
?>
<tr>
<td><?php echo $value['PlayerID']; ?></td>
<td><?php echo htmlentities($value['Nickname']); ?></td>
<td><?php echo $value['Score']; ?></td>
</tr>
<?php
}
echo '</table>';
}
}
?>
<!-- SERVER PLAYERS END -->
</div>
<!-- ANNOUNCEMENTS STARTS -->
<div class="page-section-grey-title">
<h2>Announcements:</h2>
<div class="alert alert-success" role="alert">No server announcements. Check back soon!</div>
</div>
<!-- ANNOUNCEMENTS END -->
<!-- FOOTER START -->
<footer>
<div class="container">
<div class="row">
<div class="col-lg-12">
<ul class="list-inline">
<li>
<a href="#">Home</a>
</li>
<li class="footer-menu-divider">⋅</li>
<li>
<a href="index.php">Server</a>
</li>
</ul>
<p id="copyright">Copyright © -Servername- <?php echo date("Y"); ?>. This site was coded by <?php echo OWNER; ?>. All Rights Reserved<br><br> Server IP: <?php echo SVRIP; ?></p>
</div>
</div>
</div>
</footer>
<!-- FOOTER END -->
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.******apis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
</body>
</html>
Code:
<!DOCTYPE html>
<?php include("settings.php"); ?>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?php echo SVRNAME; ?> - Error</title>
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="css/style.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="server-offline-top">The server is offline. It will be back soon! See below for details.</div>
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#"><?php echo SVRNAME; ?></a>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<li><a href="#">Home (Coming Soon)</a></li>
<li><a href="index.php">Server</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
<!-- BANNER START -->
<div class="banner-head">
<h1><?php echo SVRNAME; ?></h1>
<h3><?php echo SVRSLOGAN; ?></h3>
</div>
<!-- BANNER END -->
<!-- MAIN ERROR SECTION START -->
<div class="page-section-server-error">
<h1>Sorry, something went wrong!</h1>
<br>
<p>Looks like our server is offline or there's a fault we don't know about. Check back soon.</p>
</div>
<!-- MAIN ERROR SECTION END -->
<!-- MAIN ERROR SECTION START -->
<div class="page-section-white-title">
<h1>Information</h1>
<br>
<p>
<?php
date_default_timezone_set("Australia/Melbourne"); // Change to your timezone. Supported timezones: http://php.net/manual/en/timezones.phpnl...0.72634570 echo "<b>Time(AEDT):</b> " . date("h:i:sa");
echo "<br><br><b>Date:</b> " . date("d/m/y") . "<br><br>";
$useragent = $_SERVER ['HTTP_USER_AGENT'];
echo "<b>Broweser/System Information:</b> " . $useragent;
$started_at = microtime(true);
echo '<br><br><b>Page Loadtime:</b> ' . (microtime(true) - $started_at) . ' seconds.';
?>
</p>
</div>
<!-- MAIN ERROR SECTION END -->
<!-- FOOTER START -->
<br><footer>
<div class="container">
<div class="row">
<div class="col-lg-12">
<ul class="list-inline">
<li>
<a href="#">Home</a>
</li>
<li class="footer-menu-divider">⋅</li>
<li>
<a href="index.php">Server</a>
</li>
</ul>
<p id="copyright">Copyright © -Servername- <?php echo date("Y"); ?>. This site was coded by <?php echo OWNER; ?>. All Rights Reserved<br><br> Server IP: <?php echo SVRIP; ?></p>
</div>
</div>
</div>
</footer>
<!-- FOOTER END -->
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.******apis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
</body>
</html>