Код: Выделить всё
<?
// function send request to proxy server: which user is on $ip?
// Requere global variables $ip_checkHost and $ip_checkPort
// return:
// -1 - error; Error description is in global variable $errstr;
// 0 - none user on $ip
// >0 - user_id
function ip_check($ip)
{
$ip_checkHost="proxy.mydomain";
$ip_checkPort=4098;
global $errstr;
$fs=fsockopen($ip_checkHost,$ip_checkPort,$sockerrno,$sockerrstr);
if(!$fs){
$errstr="Socket error _ $sockerrno: $sockerrstr";
return -1;
}
fwrite($fs,"$ip\n");
if(feof($fs)){
$errstr="Conection problem: host closed conection";
return -1;
}
$res=fgets($fs,255);
if (! strlen($res) ){
$errstr = 'Server not returned result';
return -1;
}
if(($res+0)>=0){
fclose($fs);
return $res+0;
}
$errstr='Server return: ';
while(!feof($fs)){
$errstr .=fgets($fs,255)."\n";
}
fclose($fs);
return -1;
}
function auth($ip, $conn)
{
$id = ip_check($ip);
if (ip_check($ip) < 0)
return -1;
$result = mysql_query ("SELECT authproxy_id FROM staff WHERE authproxy_id=$id");
if (! $result) {
err (mysql_error());
return -1;
}
if (mysql_num_rows ($result) == 0)
return 0;
return $id;
}
?>