55502f40dc8b7c769880b10874abc9d0

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

<? 
$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 !

55502f40dc8b7c769880b10874abc9d0

leuq.myopenid.com

November 14, 2010, November 14, 2010 19:12, permalink

No rating. Login to rate!
Please some one help me ? :/
A8d3f35baafdaea851914b17dae9e1fc

Adam

November 15, 2010, November 15, 2010 02:47, permalink

No rating. Login to rate!

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);
?>
55502f40dc8b7c769880b10874abc9d0

leuq.myopenid.com

November 16, 2010, November 16, 2010 01:17, permalink

No rating. Login to rate!

I dont know about that codes so much
and the code no working :/

55502f40dc8b7c769880b10874abc9d0

leuq.myopenid.com

November 18, 2010, November 18, 2010 00:04, permalink

No rating. Login to rate!

Please can you help me?

A8d3f35baafdaea851914b17dae9e1fc

Adam

November 26, 2010, November 26, 2010 06:06, permalink

No rating. Login to rate!

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?

55502f40dc8b7c769880b10874abc9d0

leuq.myopenid.com

November 27, 2010, November 27, 2010 07:11, permalink

No rating. Login to rate!

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..

55502f40dc8b7c769880b10874abc9d0

leuq.myopenid.com

December 3, 2010, December 03, 2010 01:24, permalink

No rating. Login to rate!

some help pls?

55502f40dc8b7c769880b10874abc9d0

leuq.myopenid.com

December 3, 2010, December 03, 2010 04:14, permalink

No rating. Login to rate!

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"

2fa8694221c29a0e65838140a79d2f42

LeuQ

December 7, 2010, December 07, 2010 00:10, permalink

No rating. Login to rate!

Fatal error: Call to undefined function socket_create() in C:\wamp\www\server.php on line 2

A32ad14940368115efa800fcfd766ad7

alain.seys

December 18, 2011, December 18, 2011 12:01, permalink

No rating. Login to rate!

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); 
} 
?>
A32ad14940368115efa800fcfd766ad7

alain.seys

December 18, 2011, December 18, 2011 12:01, permalink

No rating. Login to rate!

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); 
} 
?>

Your refactoring





Format Copy from initial code

or Cancel