2

I am trying to connect FTP Server ushin php code, if i put FTP-Servaer Name Invalid then its end the script and not return false in $conn_id.

code spinet:

$conn_id = ftp_connect($_POST['ftp_server']);
if($conn_id)
{
   echo "invalid server name";
}
else
{
   if(ftp_login($conn_id, $_POST['ftp_username'], $_POST['ftp_password']))
   {
    $connection_status = 'tested';
    echo "<script>alert('Correct FTP login credentials');</script>";
   }
}

its stop script at first line and not shows echo "invalid server name";

error

ftp_connect() [function.ftp-connect]: php_network_getaddresses: getaddrinfo failed: No such host is known.

i need to alert user if he puts invalid server-name. Thanks !!!

4

2 回答 2

2

试试这个,你就完成了

$conn = @ftp_connect("ftp.funnybunnyvideos.in");
if($conn)
{
    echo 'server name is valid';
}
else
{
    echo 'server name is invalid';
}

干杯!!!

于 2012-05-17T08:40:43.427 回答
1

我认为您只需要更改if($conn_id)if($conn_id === FALSE)

编辑

尝试运行这个:

<?php
$c = ftp_connect('ftp.mozilla.org');
var_dump($c);

$c = ftp_connect('abcdefg');
var_dump($c);
?>

你应该得到这个:

resource(2) 类型(FTP 缓冲区)警告:ftp_connect()

[function.ftp-connect]:php_network_getaddresses:getaddrinfo 失败:不知道这样的主机。在第 5 行的 C:\abc\def.php 中

布尔(假)

于 2012-05-16T13:55:59.360 回答