<?
$ip = "127.0.0.1";
$port = "27020";
if (! $sock = @fsockopen($ip, $port, $num, $error, 5))
echo '<FONT COLOR=red>Offline</FONT>';
else{
echo '<FONT COLOR=lime>Online</FONT>';
fclose($sock);
}
?>
Refactorings
No refactoring yet !
leuq.myopenid.com
November 14, 2010, November 14, 2010 19:12, permalink
Please some one help me ? :/
Adam
November 15, 2010, November 15, 2010 02:47, permalink
The CS Server uses the UDP, not TCP, protocol. Since UDP is connectionless, you cannot just connect to the server to test the connection like you are trying to do in your code sample. Luckily, the CS Server implements a ping function to achieve similar functionality. You can read up on the full protocol here: http://developer.valvesoftware.com/wiki/Server_queries
<?php
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
socket_connect($socket, "localhost", 27020);
// http://developer.valvesoftware.com/wiki/Server_queries#A2A_PING
socket_write($socket, "\xFF\xFF\xFF\xFF\x69");
if (@socket_read($socket, 5) == "\xFF\xFF\xFF\xFF\x6A") {
echo '<FONT COLOR=lime>Online</FONT>';
} else {
echo '<FONT COLOR=red>Offline</FONT>';
}
socket_close($socket);
?>
leuq.myopenid.com
November 16, 2010, November 16, 2010 01:17, permalink
I dont know about that codes so much
and the code no working :/
Adam
November 26, 2010, November 26, 2010 06:06, permalink
Which part does not work? Do you get an error? Is there a firewall interfering with communication? Does your server use a different protocol than the one outlined in the link I provided?
leuq.myopenid.com
November 27, 2010, November 27, 2010 07:11, permalink
server version is :
version : 47/1.1.2.5 3382
Your script says: Offline....
but the server is online and players can connect to server..
leuq.myopenid.com
December 3, 2010, December 03, 2010 04:14, permalink
I have test it on my home web servers (Nginx, EasyPHP) and only show offline...why?
and i have testing to Dedicated webhost server and script say's "Online"
LeuQ
December 7, 2010, December 07, 2010 00:10, permalink
Fatal error: Call to undefined function socket_create() in C:\wamp\www\server.php on line 2
alain.seys
December 18, 2011, December 18, 2011 12:01, permalink
you port is not availible did you port forward ? add the port to you exceptions in your firewall
i tested the script on ma Local network using WAMP and i tested on my public ip WAN and they do work when i turn the service on it display's online & off ->offline i did not modify the script i just copied and pasted , and it worked , my suggestion check you php.ini if it has full acces and also check appache that all permission are Allow deny and not Deny Allow i have only set my htacces files to Deny
<?php
$ip = "178.118.95.3";
$port = "27025";
if (! $sock = @fsockopen($ip, $port, $num, $error, 5))
echo '<FONT COLOR=red>Offline</FONT>';
else{
echo '<FONT COLOR=lime>Online</FONT>';
fclose($sock);
}
?>
<p><b>Private [LAN]</b></p>
<?php
$ip = "192.168.0.172";
$port = "27025";
if (! $sock = @fsockopen($ip, $port, $num, $error, 5))
echo '<FONT COLOR=red>Offline</FONT>';
else{
echo '<FONT COLOR=lime>Online</FONT>';
fclose($sock);
}
?>
alain.seys
December 18, 2011, December 18, 2011 12:01, permalink
you port is not availible did you port forward ? add the port to you exceptions in your firewall
i tested the script on ma Local network using WAMP and i tested on my public ip WAN and they do work when i turn the service on it display's online & off ->offline i did not modify the script i just copied and pasted , and it worked , my suggestion check you php.ini if it has full acces and also check appache that all permission are Allow deny and not Deny Allow i have only set my htacces files to Deny
<?php
$ip = "178.118.95.3";
$port = "27025";
if (! $sock = @fsockopen($ip, $port, $num, $error, 5))
echo '<FONT COLOR=red>Offline</FONT>';
else{
echo '<FONT COLOR=lime>Online</FONT>';
fclose($sock);
}
?>
<p><b>Private [LAN]</b></p>
<?php
$ip = "192.168.0.172";
$port = "27025";
if (! $sock = @fsockopen($ip, $port, $num, $error, 5))
echo '<FONT COLOR=red>Offline</FONT>';
else{
echo '<FONT COLOR=lime>Online</FONT>';
fclose($sock);
}
?>
Hi all i'm new here i want one php script for online/offline status counter-strike server
I have found this but is not working
Any help please ? i want it