PDA

View Full Version : check connection, help !!!



kamikaze5141
May 25th, 2009, 05:51 AM
i wanna use php code to check connection, my code is as below, but it is not working can u guys point out the error for me !!! thx....



<?php
function is_connected();

function is_connected()
{

$connected = @fsockopen("www.google.com");
if ($connected){
$is_conn = true;
fclose($connected);
}else{
$is_conn = false;
}
return $is_conn;

}
?>

crayzee
May 26th, 2009, 04:31 AM
try these:

1. get rid of the @ symbol.
2. put the function call after the function declaration.

Nevo
May 26th, 2009, 07:35 AM
Plus you don't want "function" infront of the call?



<?php
function is_connected()
{

$connected = fsockopen("www.google.com");
if ($connected){
$is_conn = true;
fclose($connected);
}else{
$is_conn = false;
}
return $is_conn;

}
$foo = is_connected();
?>