FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Connect to a IP.





Diablosblizz
Okay, I was wondering if I could use php to connect to a server (but not actually go to the server). For example:

If the server (specified by my ip and port) is accessible, then it will show:

Server status: Online!

and then if its offline then the script will show:

Server status: Offline

Is this possible? Thanks.
fromegame
Yep it's possible, I made it also, I will post it in 10 seconds, please wait Smile

Code:

<?php
function pingDomain($domain){
    $starttime = microtime(true);
    $file      = fsockopen ($domain, 80, $errno, $errstr, 5); // 80 = port, 5 = times
    $stoptime = microtime(true);
    $status    = 0;

    if (!$file) $status = -1;  // Site is down
    else {
        fclose($file);
        $status = ($stoptime - $starttime) * 1000;
        $status = floor($status);
    }
    return $status;
}

$status = pingDomain("216.32.85.170"); // Change to your IP
if($status != -1) {
   echo "Online";
   }else{
   echo "Offline";   
}
?>


Should work

Example: www.frome.frih.net/ping.php
Diablosblizz
Two questions now.. One.. can I get rid of this:

Quote:
Warning: fsockopen() [function.fsockopen]: unable to connect to 24.141.134.127:90 in /home/diablos/domains/gamerzheaven.frih.net/public_html/!~!~!/index.php on line 24


It also shows offline at the bottem, and my server is not 24/7 so this error may screw up my layout..

Second..

Is it possible to resize a pop-up link?

I am using javascript right now but its not letting me use a image.


Thanks!
fromegame
Add this code at the top of your .php file:

Code:
error_reporting(0);


About your second question.. I don't really get what you want to do, sorry Rolling Eyes
Diablosblizz
Alright, for the second one, I would like a image to repersent a link (this is html)...

Once a visitor clicks on the link, it will launch a "_blank" but, it will be resized, and it can't be resized.

Do you understand now?
hexkid
Diablosblizz wrote:
can I get rid of this:

Quote:
Warning: fsockopen() [function.fsockopen]: unable to connect to 24.141.134.127:90 in /home/diablos/domains/gamerzheaven.frih.net/public_html/!~!~!/index.php on line 24

Use the error control operator.
Diablosblizz
Fixed that already, thanks for that though.
Related topics
How can I connect to cpanel?
addon domains / rndc: connect failed
Connect to MySql database
routing a localhost port to an extarnal ip so that programs
Cannot connect via FTP. Have tried everything...
routers and IP addresses
Mysql wont connect Hmmm
Can I connect to frihost mysql from my home computer?
Getting host to connect to my local mysql?
[SOLVED] Banning people from visiting my IP Address?
MySQL wont let me connect.
IP Whitelisting Windows 7
Newbie with some questions
Need Help my FTP cannot connect to the server!
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.