1

我编写了一个不错的脚本,但我不断得到

Error on line 29: Parse error, unexpected T_IF(if)

我试过调试代码,浪费了很多时间。但是什么都没有,出来了。

这是我的代码。

<?php

  include("geoip.inc");
$ip=$_SERVER['REMOTE_ADDR'];
$gi = geoip_open("GeoIP.dat",GEOIP_STANDARD);

$country_code = geoip_country_code_by_addr($gi, "$ip");
$referrer=$_SERVER['HTTP_REFERER'];
// Country name is not used so commented
// Get Country Name based on source IP
//$country = geoip_country_name_by_addr($gi, "$ip");
$real=0;
geoip_close($gi);

if(strstr(strtolower($_SERVER['HTTP_USER_AGENT']), "googlebot")) {
    $real = 1;  
}
else {
                if ($_COOKIE['iwashere'] != "yes")  {
                setcookie("iwashere", "yes", time()+315360000); 
                            if ($country_code="IN") {
                                    if(preg_match('/google/i', $referrer)) {
                                    $key = "g17x9erm28n7cgifddssfqhgorjf3e"; // Account API Key
                                    $ip = $_SERVER['REMOTE_ADDR']; // IP to Lookup

                                    $result = file_get_contents('http://www.ipqualityscore.com/api/ip_lookup.php?KEY='.$key.'&IP='.$ip);
                                    $real=$result
//$result will be equal to 1 for detected proxies & vpns or equal to 0 for clean IP's
                                            {if($real==0)
                                            {setcookie("testcookie", "testvalue");  
                                                        if( isset( $_COOKIE['testcookie'] ) ) {
                                                                if (isset($_POST['jstest'])) {
                                                                    $nojs = FALSE;
                                                                    } else {
  // create a hidden form and submit it with javascript
                                                                    echo '<form name="jsform" id="jsform" method="post" style="display:none">';
                                                                    echo '<input name="jstest" type="text" value="true" />';
                                                                    echo '<script language="javascript">';
                                                                    echo 'document.jsform.submit();';
                                                                    echo '</script>';
                                                                    echo '</form>';
  // the variable below would be set only if the form wasn't submitted, hence JS is disabled
                                                                    $nojs = TRUE;
    }
                                                                                if ($nojs){
    $real=1;
 }


}
else    
$real=1;        
}
else
$real=1;

        } else 
            $real = 1;

    }
 else {
    $real = 1;
}
          }  }

if ($real==1) {
    include_once('Biggenius1.htm');

}

?>

如果在里面。请给我建议,关于如何避免这些错误。还有其他方法可以用多个嵌套的 if 语句编写这种复杂的脚本吗?

请发布完整的代码:

4

5 回答 5

0

以下是我发现的几个错误:

  1. if ($country_code="IN"):这是一个赋值而不是比较,总是返回true
  2. $real=$result;:最后缺少终止符
于 2012-05-01T06:30:49.017 回答
0

第 29行应以$real=$result分号结尾,下一行{if($real==0)应为if($real==0){.

错误消息是您的朋友,它建议您查看第 29 行。

于 2012-05-01T06:32:29.797 回答
0

您在 if 条件之前放置了一个大括号 //$result 对于检测到的代理和 vpns 将等于 1 或对于干净 IP 的 {if($real==0) 等于 0

删除它然后你的错误将被删除

于 2012-05-01T06:32:31.140 回答
0

通过阅读您的代码,似乎我能找到的唯一错误是:

{if($real==0)

和:

$real=$result

应该改成:

if($real==0){

和:

$real=$result;
于 2012-05-01T06:34:01.013 回答
0

试试这个

$real = 0;
geoip_close($gi);

if (strstr(strtolower($_SERVER['HTTP_USER_AGENT']), "googlebot")) {
    $real = 1;
} else {
    if ($_COOKIE['iwashere'] != "yes") {
        setcookie("iwashere", "yes", time() + 315360000);
        if ($country_code = "IN") {
            if (preg_match('/google/i', $referrer)) {
                $key = "g17x9erm28n7cgifddssfqhgorjf3e"; // Account API Key
                $ip = $_SERVER['REMOTE_ADDR']; // IP to Lookup

                $result = file_get_contents('http://www.ipqualityscore.com/api/ip_lookup.php?KEY=' . $key . '&IP=' . $ip);
                $real = $result;
//$result will be equal to 1 for detected proxies & vpns or equal to 0 for clean IP's {
                    if ($real == 0) {
                        setcookie("testcookie", "testvalue");
                        if (isset($_COOKIE['testcookie'])) {
                            if (isset($_POST['jstest'])) {
                                $nojs = FALSE;
                            } else {

                            }
                            // create a hidden form and submit it with javascript
                            echo '<form name="jsform" id="jsform" method="post" style="display:none">';
                            echo '<input name="jstest" type="text" value="true" />';
                            echo '<script language="javascript">';
                            echo 'document.jsform.submit();';
                            echo '</script>';
                            echo '</form>';
                            // the variable below would be set only if the form wasn't submitted, hence JS is disabled
                            $nojs = TRUE;
                        }
                        if ($nojs) {
                            $real = 1;
                        }
                    }
                    else
                        $real = 1;
                }
                else
                $real = 1;
            } else
                $real = 1;
        }
        else {
            $real = 1;
        }

}

if ($real == 1) {
    include_once('Biggenius1.htm');
}
于 2012-05-01T06:35:25.263 回答