I programmed a website for minecraft servers and I have a problem.
my website is:
Serv-Craft
My host is iPage and on the servers section I check if the server is offline or online.
The problem is that all of the servers that I check are online and the website output that they are online.
I tried to put my website on another host and my code worked
The other site: Serv-Craft Temp Host
What to do??
My code is:
<?php
function GetServerStatus($site, $port)
{
$status = array("<img src='images/icons/off.png' title='Offline'><br>Offline", "<img src='images/icons/online.png' title='Online!'><br>Online");
$fp = fsockopen($site, $port, $errno, $errstr, 0.35);
if (!$fp) {
return $status[0];
} else {
return $status[1];
}
}
print_r(GetServerStatus($server_ip, $server_port));
?>
Please check phpinfo if allow url fopen is activated.
Related
I have a strange thing, fsockopen works fine with PHP 5.5 on WAMP, but fails with PHP 5.6 (also WAMP, same server).
I am using a library, there is this code:
$url = parse_url($uri);
if ('https' == $url['scheme']) {
$host = 'ssl://'.$url['host'];
$port = 443;
} else {
$host = $url['host'];
$port = 80;
}
$fp = fsockopen($host, $port, $errno, $errstr, 30);
if (!$fp) {
throw new WebToPayException(sprintf('Cannot connect to %s', $uri), WebToPayException::E_INVALID);
}
It returns false (empty), $errno is 0, $errstr is empty.
I've checked differences of enabled PHP extensions, both for 5.5 and 5.6 in WAMP, everything is the same. It's same computer, same Apache server, and there are two PHP versions.
I've Googled for this, but couldn't find the solution. It is something PHP configuration related but I couldn't find what it is.
It would be awesome if someone could help :) Thanks!
I am about to write a function which returns true or false. If the function is able to connect to the game server (doesn't need anything further, just to check if it's running) via UDP and a specific ip, it'll return true. If not, it'll return false. Unfortunately, I didn't find anything useful by searching the web.
Edit: For TCP, I'm using this and it's working like a charm.
function loginServer()
{
$ipAddr = "localhost";
$port = 1234;
$fp = fsockopen($ipAddr, $port, $errno, $errstr);
if(!$fp)
{
return false;
}
else
{
fclose($fp);
return true;
}
}
I'm using a [PHP Telnet Class][1] to connect to server via telnet to send commands. It connects to the server successfully but it fails to login in..
require_once "PHPTelnet.php";
$telnet = new PHPTelnet();
// if the first argument to Connect is blank,
// PHPTelnet will connect to the local host via 127.0.0.1
$result = $telnet->Connect('172.20.66.100','username','password');
if ($result == 0) {
$telnet->DoCommand('another command', $result);
echo $result;
$telnet->Disconnect();}
===============================================================================
UPDATE:
My script is working, there was some conflict going on with my virtual machine......
Try this:
$url = 'tcp://ADDRESS_HERE:PORT_HERE';
$fp = stream_socket_client($url, $errno, $errstr, 10);
if (!$fp) {
echo ("$errstr ($errno)<br />\n");
exit;
} else {
$command = 'execute_command_line' . PHP_EOL;
fwrite($fp, $out);
stream_set_blocking($fp, true);
while (!feof($fp)) {
$output = stream_get_contents($fp);
}
fclose($fp);
echo output;
}
According to the documentation in the PHPTelnet website you have the parameters to the constructor in the wrong order.
In the library's documentation there is the following example:
$result = $telnet->Connect('www.somewhere.com','login name','password');
Therefore, you should have:
$result = $telnet->Connect('172.20.66.100','username','password');
Source: PHPTelnet Documentation
EDIT
You mentioned that you get erro nÂș 3. In the source code, error 3 has the following description: Connect failed: Login Failed
Which points to the following URL:
Information about Error 3
Which lists the possible causes as:
You misspelled your username or password (i.e. Your credentials are wrong)
Telnet service is not available for your username and password (i.e. Your user does not have permissions to access the Telnet service)
Is there any reliable way via PHP to check if a local WebServer (php4) can access a remote SSL address ?
https://xxx.yyy.com
port 443 ?
All I'm interested in ensuring is the connection from the WebServer to the remote address is working and on port 443. I'm not bothered about checking certificates etc..
Thanks
UPDATE:
I've tried this, but is it reliable ?
<?php
function checkConnection()
{
$conn = #fsockopen("www.abc.com", 443, $errno, $errstr, 30);
if ($conn)
{
$status = "Connection is OK";
fclose($conn);
}
else
{
$status = "NO Connection<br/>\n";
$status .= "$errstr ($errno)";
}
return $status;
}
echo checkConnection();
?>
I'm trying to use a script to query if a Shoutcast Server is online or offline. The code below is what I'm using at the moment.
$vt_ip = "ip";
$vt_port = "port";
$output = #fsockopen($vt_ip, $vt_port, $errno, $errstr, 2);
if (!$output) {
echo "<FONT CLASS=f1 COLOR=#DD0000><B>OFFLINE</B></FONT>";
} else {
echo "<FONT CLASS=f1 COLOR=#00DD00><B>ONLINE</B></FONT>";
}
#fclose($output);
But it doesn't update, it is stuck on Offline status.
Any help would be greatly appreciated.
$vt_ip = "ip";
$vt_port = "port";
$conn = fsockopen($vt_ip, $vt_port, $errno, $errstr, 2);
if(!$conn){
echo $errno;
}else{
fwrite($conn, "\n");
$output = fread($conn, 1024);
fclose($conn);
if ($output == "") {
echo "<FONT CLASS=f1 COLOR=#DD0000><B>OFFLINE</B></FONT>";
} else {
echo "<FONT CLASS=f1 COLOR=#00DD00><B>ONLINE</B></FONT>";
}
}
It isn't enough to simply make a TCP connection to a SHOUTcast server to determine if the stream is working. In fact, a SHOUTcast server that is running will always accept yourTCP connection, even if there is no stream for playback.
You must connect, request the stream, and then check the return status code. Once connected, send this data:
GET /; HTTP/1.0
Follow that by a \r\n\r\n. Now, read data back from the stream until you get the \r\n\r\n. Then, you can disconnect. Check the status code from the first response line and see if it's 200. If it is, you've got an active stream.