2012-05-23 148 views
0

使用secureimage溶液以生成驗證碼的代碼無法生成驗證碼的圖像,內容爲已輸出

我有CHROM控制檯上此錯誤

資源解釋爲圖像,但與MIME類型文本傳輸IM/HTML

並在此URL entring時直接用作圖片src

securimage_show.php?SID = fa5e1eb19c3a534885632e

我有此錯誤

無法生成驗證碼的圖像,內容爲已輸出。 這很可能是由於配置錯誤或PHP錯誤被送到 瀏覽

有人有想法?

注:我的作品在本地主機wampserver而不是遠程服務器

編輯於:

從驗證碼的開源代碼生成PHP錯誤代碼:

protected function output() 
{ 
    if ($this->canSendHeaders() || $this->send_headers == false) { 
     if ($this->send_headers) { 
      // only send the content-type headers if no headers have been output 
      // this will ease debugging on misconfigured servers where warnings 
      // may have been output which break the image and prevent easily viewing 
      // source to see the error. 
      header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 
      header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT"); 
      header("Cache-Control: no-store, no-cache, must-revalidate"); 
      header("Cache-Control: post-check=0, pre-check=0", false); 
      header("Pragma: no-cache"); 
     } 

     switch ($this->image_type) { 
      case self::SI_IMAGE_JPEG: 
       if ($this->send_headers) header("Content-Type: image/jpeg"); 
       imagejpeg($this->im, null, 90); 
       break; 
      case self::SI_IMAGE_GIF: 
       if ($this->send_headers) header("Content-Type: image/gif"); 
       imagegif($this->im); 
       break; 
      default: 
       if ($this->send_headers) header("Content-Type: image/png"); 
       imagepng($this->im); 
       break; 
     } 
    } else { 
     echo '<hr /><strong>' 
      .'Failed to generate captcha image, content has already been ' 
      .'output.<br />This is most likely due to misconfiguration or ' 
      .'a PHP error was sent to the browser.</strong>'; 
    } 

    imagedestroy($this->im); 
    restore_error_handler(); 

    if (!$this->no_exit) exit; 
} 
+0

你能提供一些你的代碼? –

+0

我會看到它,但它適用於本地主機,但不適用於遠程服務器 –

+1

您忘了包含關鍵的if語句,其計算結果爲false ... – jeroen

回答

0

失敗生成驗證碼圖片,內容已經輸出。這很可能是由於配置錯誤或PHP錯誤被送到瀏覽

我認爲你是在你的web.config

+0

不幸的是它是一個共享服務器,無法配置 –

+0

web.config?他的問題是關於PHP,這聽起來像你指的是一個.NET Web應用程序... – Travitron

0

通過這一聲明,其值false來看缺失參照的DLL:

if ($this->canSendHeaders() || $this->send_headers == false) { 

在調用output函數之前,您已將東西發送到瀏覽器。

爲了能夠使用該功能,您必須確保沒有任何內容被髮送到瀏覽器;沒有空行或空格前打開<?php標籤,沒有echo陳述等

+0

thx回覆,問題是爲什麼它在本地工作 –

+0

@khaled_webdev可能是一樣簡單的空間或一條新線這會被wamp忽略,但不會被服務器忽略。 – jeroen

+0

如果($ this-> canSendHeaders()|| $ this-> send_headers == false)改變if(1 == 1)來忽略它,我改變了這個條件。這有沒有副作用? –

0

今天早上有同樣的問題,我已經做了一個月前的發展,而今天部署我忘記了我放置回聲在securimage.php的頂部,希望這能幫助

+0

感謝你,我剛剛刪除了錯誤信息的條件,並且像魅力一樣沒有任何問題,也許不是最好的解決方案,但它適用於我。是的,我必須驗證任何回聲或空行,如推薦作者jeron。 –

2

快速修復:

只需更換canSendHeaders功能securimage。PHP文件

protected function canSendHeaders() { 

    if (headers_sent()) { 

     // output has been flushed and headers have already been sent 
     return false; 
    } else if (strlen((string) ob_get_contents()) > 0) { 
     // headers haven't been sent, but there is data in the buffer that will break image and audio data 
     return false; 
    } 

    return true; 
} 

protected function canSendHeaders() { 

    ob_get_clean(); 

    if (headers_sent()) { 

     // output has been flushed and headers have already been sent 
     return false; 
    } else if (strlen((string) ob_get_contents()) > 0) { 
     // headers haven't been sent, but there is data in the buffer that will break image and audio data 
     return false; 
    } 

    return true; 
}