2012-02-25 60 views
0

最近我在我的上傳腳本中實現了一個ReCAPTCHA腳本。在做其他事情之前檢查recaptcha?

什麼問題是,是,它等待,直到它檢查的ReCaptcha之前,整個上傳後...

誰能告訴我什麼,我做錯了什麼?

<?php 
include 'config.php'; 
$download = "caches/" . $_POST['email'] . ".zip"; 
$revision = $_POST['email']; 
$details = $_POST['password']; 
$ip  = $_SERVER['REMOTE_ADDR']; 
if ($revision >= 300 && $revision <= 499) { 
    $table = "300caches"; 
} else if ($revision >= 500 && $revision <= 599) { 
    $table = "500caches"; 
} else if ($revision >= 600 && $revision <= 800) { 
    $table = "600caches"; 
} else { 
    header('Location: error.php?err=rev'); 
} 
require_once('captcha/recaptchalib.php'); 
$privatekey = ""; 
$resp  = recaptcha_check_answer($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); 
if (!$resp->is_valid) { 
    header('Location: error.php?err=rec'); 
} 
if (!$_GET['act']) { 
    if ((($_FILES["file"]["type"] == "application/zip") || ($_FILES["file"]["type"] == "application/octet-stream")) && ($_FILES["file"]["size"] < 315000000)) { 
     if ($_FILES["file"]["error"] > 0) { 
      header('Location: error.php?err=unknown'); 
     } else { 
      if (file_exists("caches/" . $_FILES["file"]["name"])) { 
       header('Location: error.php?err=fx&name=' . $_FILES["file"]["name"]); 
      } else { 
       $checkFile = "main_file_cache.dat"; 
       $checkFile2 = "main_file_cache.dat0"; 
       $checkExe = "exe"; 
       $zip  = new ZipArchive; 
       $res  = $zip->open($_FILES["file"]["tmp_name"]); 
       if (!is_numeric($zip->locateName($checkExe))) { 
        if ($res === TRUE) { 
         if (is_numeric($zip->locateName($checkFile)) || is_numeric($zip->locateName($checkFile2))) { 
          $uploaded = move_uploaded_file($_FILES["file"]["tmp_name"], "caches/" . $revision . ".zip"); 
          if ($uploaded) { 
           $sql = "INSERT INTO $table(revision, link, details, ip)VALUES('$revision', '$download', '$details', '$ip')"; 
           $result = mysql_query($sql); 
           if ($result) { 
            header("Location: index.php"); 
           } else { 
            header("Location: error.php?err=sql"); 
           } 
          } 
          $zip->close(); 
         } else { 
          header("Location: error.php?err=nc"); 
         } 
        } else { 
         header("Location: error.php?err=nc"); 
        } 
       } else { 
        header("Location: error.php?err=nc"); 
       } 
      } 
     } 
    } else { 
     header('Location: error.php?err=if&name=' . $_FILES["file"]["name"]); 
    } 
} 
?> 
+0

在CAPTCHA失敗的'header()'後放一個退出 – random 2012-02-25 04:09:54

+0

@random我試過了,它仍然等待上傳完成。 – Laszki 2012-02-25 04:10:24

回答

1

當然它等待上傳完成。

將數據發送到表單提交中的服務器,無論是否AJAX。 當您調用$ _POST時,不會從瀏覽器中檢索表單數據。

解決方案如果您首先使用ajax檢查另一個ajax頁面並檢查驗證碼是否正確,並返回可用於文件上傳的令牌。

我不知道如何在普通文件上傳的情況下解決這個問題,除了有一個用戶在可以訪問上傳頁面之前輸入驗證碼的頁面。

+0

另外,你可能想要實現一個try/catch語句,它會使代碼更清潔。 – MichaelH 2012-02-25 04:19:15

相關問題