向上面发送php变量以防止循环

向上面发送php变量以防止循环,php,html,loops,Php,Html,Loops,我有一个脚本,其中我使用die来防止函数的连续循环。但是如果我把它放在html上面,html脚本也会停止,所以我把它放在html下面,但是所有变量都会在实际网站下面得到响应。我怎样才能确保这个get被回响到我想要的地方,而不是在网站下面?或者有没有一种不同于使用模具的方法?这是函数的代码: function QueryWhoisServer($whoisserver, $domain) { $port = 43; $timeout = 5; $errm = "<p1

我有一个脚本,其中我使用die来防止函数的连续循环。但是如果我把它放在html上面,html脚本也会停止,所以我把它放在html下面,但是所有变量都会在实际网站下面得到响应。我怎样才能确保这个get被回响到我想要的地方,而不是在网站下面?或者有没有一种不同于使用模具的方法?这是函数的代码:

function QueryWhoisServer($whoisserver, $domain) {
    $port = 43;
    $timeout = 5;
    $errm = "<p1>No connection could be made</p1>";
    $fp = @fsockopen($whoisserver, $port, $errno, $errstr, $timeout) or die($errm); 
    fputs($fp, $domain . "\r\n");
    $out = "";
    while (!feof($fp)) {
        $out .= fgets($fp);
    }
    fclose($fp);

    $res = "";
    if((strpos(strtolower($out), "error") === FALSE) && (strpos(strtolower($out), "not allocated") === FALSE)) {
        $rows = explode("\n", $out);
        foreach($rows as $row) {
            $row = trim($row);
            if(($row != ':') && ($row != '#') && ($row != '%')) {
                $res .= $row."<br>";
            }
        }
    }
    return $res;
}
函数QueryWhoisServer($whoisserver,$domain){
$port=43;
$timeout=5;
$errm=“无法建立连接”;
$fp=@fsockopen($whoisserver、$port、$errno、$errstr、$timeout)或die($errm);
fputs($fp,$domain.\r\n”);
$out=“”;
而(!feof($fp)){
$out.=fgets($fp);
}
fclose($fp);
$res=”“;
if((strpos(strtolower($out),“error”)==FALSE)和&(strpos(strtolower($out),“未分配”)==FALSE)){
$rows=分解(“\n”,$out);
foreach($行作为$行){
$row=修剪($row);
如果($row!=':')&&($row!='#')&&($row!='%)){
$res.=$row.“
”; } } } 返回$res; }
关键字
break
打破任何循环,只需使用它而不是
die


如果有嵌套循环,请小心,因为break只会退出最里面的循环。奇怪的是,在php中,可以使用break(2)从两个循环中中断。不过,我不会这么做。

关键字
break
打破了任何循环,只需使用它而不是
die


如果有嵌套循环,请小心,因为break只会退出最里面的循环。奇怪的是,在php中,可以使用break(2)从两个循环中中断。不过,我不会这么做。

关键字
break
打破了任何循环,只需使用它而不是
die


如果有嵌套循环,请小心,因为break只会退出最里面的循环。奇怪的是,在php中,可以使用break(2)从两个循环中中断。不过,我不会这么做。

关键字
break
打破了任何循环,只需使用它而不是
die

如果有嵌套循环,请小心,因为break只会退出最里面的循环。奇怪的是,在php中,可以使用break(2)从两个循环中中断。不过,我不会这么做。

die()停止所有PHP执行。很少有人真的想这么做

相反,您应该查看try-catch构造以及抛出和捕获异常

function QueryWhoisServer($whoisserver, $domain) {
    try {
        $port = 43;
        $timeout = 5;
        $errm = "<p1>No connection could be made</p1>";
        $fp = @fsockopen($whoisserver, $port, $errno, $errstr, $timeout);

        if (!fp) {
            throw new Exception ("Couldn't open socket.");
        }
        //after the exception is thrown, the rest of this block will not execute.

        fputs($fp, $domain . "\r\n");
        $out = "";
        while (!feof($fp)) {
            $out .= fgets($fp);
        }
        fclose($fp);

        $res = "";
        if((strpos(strtolower($out), "error") === FALSE) && (strpos(strtolower($out), "not allocated") === FALSE)) {
            $rows = explode("\n", $out);
            foreach($rows as $row) {
                $row = trim($row);
                if(($row != ':') && ($row != '#') && ($row != '%')) {
                    $res .= $row."<br>";
                }
            }
        }
        return $res;
    } catch (Exception $e) {
        //this block will be executed if any Exception is caught, including the one we threw above.
        //you can handle the error here or rethrow it to pass it up the execution stack.
        return "";
    }

}
函数QueryWhoisServer($whoisserver,$domain){
试一试{
$port=43;
$timeout=5;
$errm=“无法建立连接”;
$fp=@fsockopen($whoisserver,$port,$errno,$errstr,$timeout);
如果(!fp){
抛出新异常(“无法打开套接字”);
}
//抛出异常后,该块的其余部分将不会执行。
fputs($fp,$domain.\r\n”);
$out=“”;
而(!feof($fp)){
$out.=fgets($fp);
}
fclose($fp);
$res=”“;
if((strpos(strtolower($out),“error”)==FALSE)和&(strpos(strtolower($out),“未分配”)==FALSE)){
$rows=分解(“\n”,$out);
foreach($行作为$行){
$row=修剪($row);
如果($row!=':')&&($row!='#')&&($row!='%)){
$res.=$row.“
”; } } } 返回$res; }捕获(例外$e){ //如果捕获到任何异常(包括我们在上面抛出的异常),将执行此块。 //您可以在此处处理该错误,也可以重新调用它以将其传递到执行堆栈。 返回“”; } }
die()停止所有PHP执行。很少有人真的想这么做

相反,您应该查看try-catch构造以及抛出和捕获异常

function QueryWhoisServer($whoisserver, $domain) {
    try {
        $port = 43;
        $timeout = 5;
        $errm = "<p1>No connection could be made</p1>";
        $fp = @fsockopen($whoisserver, $port, $errno, $errstr, $timeout);

        if (!fp) {
            throw new Exception ("Couldn't open socket.");
        }
        //after the exception is thrown, the rest of this block will not execute.

        fputs($fp, $domain . "\r\n");
        $out = "";
        while (!feof($fp)) {
            $out .= fgets($fp);
        }
        fclose($fp);

        $res = "";
        if((strpos(strtolower($out), "error") === FALSE) && (strpos(strtolower($out), "not allocated") === FALSE)) {
            $rows = explode("\n", $out);
            foreach($rows as $row) {
                $row = trim($row);
                if(($row != ':') && ($row != '#') && ($row != '%')) {
                    $res .= $row."<br>";
                }
            }
        }
        return $res;
    } catch (Exception $e) {
        //this block will be executed if any Exception is caught, including the one we threw above.
        //you can handle the error here or rethrow it to pass it up the execution stack.
        return "";
    }

}
函数QueryWhoisServer($whoisserver,$domain){
试一试{
$port=43;
$timeout=5;
$errm=“无法建立连接”;
$fp=@fsockopen($whoisserver,$port,$errno,$errstr,$timeout);
如果(!fp){
抛出新异常(“无法打开套接字”);
}
//抛出异常后,该块的其余部分将不会执行。
fputs($fp,$domain.\r\n”);
$out=“”;
而(!feof($fp)){
$out.=fgets($fp);
}
fclose($fp);
$res=”“;
if((strpos(strtolower($out),“error”)==FALSE)和&(strpos(strtolower($out),“未分配”)==FALSE)){
$rows=分解(“\n”,$out);
foreach($行作为$行){
$row=修剪($row);
如果($row!=':')&&($row!='#')&&($row!='%)){
$res.=$row.“
”; } } } 返回$res; }捕获(例外$e){ //如果捕获到任何异常(包括我们在上面抛出的异常),将执行此块。 //您可以在此处处理该错误,也可以重新调用它以将其传递到执行堆栈。 返回“”; } }
die()停止所有PHP执行。很少有人真的想这么做

相反,您应该查看try-catch构造以及抛出和捕获异常

function QueryWhoisServer($whoisserver, $domain) {
    try {
        $port = 43;
        $timeout = 5;
        $errm = "<p1>No connection could be made</p1>";
        $fp = @fsockopen($whoisserver, $port, $errno, $errstr, $timeout);

        if (!fp) {
            throw new Exception ("Couldn't open socket.");
        }
        //after the exception is thrown, the rest of this block will not execute.

        fputs($fp, $domain . "\r\n");
        $out = "";
        while (!feof($fp)) {
            $out .= fgets($fp);
        }
        fclose($fp);

        $res = "";
        if((strpos(strtolower($out), "error") === FALSE) && (strpos(strtolower($out), "not allocated") === FALSE)) {
            $rows = explode("\n", $out);
            foreach($rows as $row) {
                $row = trim($row);
                if(($row != ':') && ($row != '#') && ($row != '%')) {
                    $res .= $row."<br>";
                }
            }
        }
        return $res;
    } catch (Exception $e) {
        //this block will be executed if any Exception is caught, including the one we threw above.
        //you can handle the error here or rethrow it to pass it up the execution stack.
        return "";
    }

}
函数QueryWhoisServer($whoisserver,$domain){
试一试{
$port=43;
$timeout=5;
$errm=“无法建立连接”;
$fp=@fsockopen($whoisserver,$port,$errno,$errstr,$timeout);
如果(!fp){
抛出新异常(“无法打开套接字”);
}
//抛出异常后,该块的其余部分将不会执行。
fputs($fp,$domain.\r\n”);
$out=“”;
而(!feof($fp)){
$out.=fgets($fp);
}
fclose($fp);
$res=”“;