2013-07-06 38 views
0

試圖將recaptcha添加到我的php表單中,我從Google提供的示例php代碼開始。我插入下面的代碼,到form1.php:將php代碼插入html代碼截斷

<html> 
<body> 

<h3>You can use the following form to contact the author:</h3> 

<form action="send1.php" method="post" name="contactform"> 

<table width="450px"> 
<tbody> 
<tr> 
<td valign="top"><label for="first_name">First Name *</label></td> 
<td valign="top"><input type="text" maxlength="50" name="first_name" size="30" /></td> 
</tr> 
<tr> 
<td valign="top"><label for="last_name">Last Name *</label></td> 
<td valign="top"><input type="text" maxlength="50" name="last_name" size="30" /></td> 
</tr> 
<tr> 
<td valign="top"><label for="email">Email Address *</label></td> 
<td valign="top"><input type="text" maxlength="80" name="email" size="30" /></td> 
</tr> 
<tr> 
<td valign="top"><label for="telephone">Telephone Number</label></td> 
<td valign="top"><input type="text" maxlength="30" name="telephone" size="30" /></td> 
</tr> 
<tr> 
<td valign="top"><label for="comments">Comments *</label></td> 
<td valign="top"><textarea cols="30" maxlength="1000" name="comments" rows="6"></textarea></td> 
</tr> 
<tr> 
<td></td> 
<td style="text-align: left;" colspan="2"> 
<?php 
      require_once('recaptchalib.php'); 
      $publickey = "GOkj44zG4SZKeo3PYMTmPYySzp7JPdq4"; 
      echo recaptcha_get_html($publickey); 
?> 
<input type="submit" value="Submit" /></td> 
</tr> 
</tbody> 
</table> 
</form> 
</body> 
</html> 

不是看到captcha圖像的,我發現,即使提交按鈕消失。在瀏覽器中查看源代碼時,我發現代碼在行<td style="text-align: left;" colspan="2">後被截斷。從php代碼開始,頁面上沒有顯示任何內容。

這不是將php代碼插入html的正確方法嗎?爲什麼在PHP代碼的開頭截斷html代碼?

+0

你確定recaptchalib.php和這個form1.php在同一個目錄嗎? – Ron

回答

0

This is the proper way。

但是,如果您沒有正確下載或安裝所有文件,可能是錯誤。這樣的錯誤可能會立即停止腳本執行,因此也會阻止在腳本之後輸出的靜態html。

該腳本的語法似乎是正確的,並且顯然嘗試運行它的事實表明也設置了PHP。所以我的猜測是無法找到recaptchalib.php,或者它包含其他無法找到的文件。

如果在輸出中沒有出現任何錯誤,您可能需要檢查錯誤日誌或啓用錯誤輸出,以便更好地瞭解正在發生的事情。

+0

這真是奇怪。我已經重新檢查並確認文件recaptchalib.php存在於同一目錄中,並且具有正確的文件名。我甚至嘗試在require_once函數中添加完整路徑。當我嘗試直接通過輸入url來運行它時,會調用recaptchalib.php。 – Droidzone

+0

再次檢查文檔,顯然你只需要那一個文件。儘管如此,包括它可能會導致問題,但沒有一個適當的錯誤信息,它會猜測。 – GolezTrol

+0

我啓用了'error_reporting(E_ALL); ini_set('display_errors','1');'。我也看着Apache日誌。它只顯示'[06/Jul/2013:21:51:15 +0400]「GET/phpscripts/form1 HTTP/1.1」200 395「 - 」「Mozilla/5.0(Windows NT 6.1; WOW64)AppleWebKit/537.36 ,像Gecko)Chrome/27.0.1453.116 Safari/537.36「',我認爲這意味着沒有顯示錯誤?我甚至通過bash中的'php form1.php'來執行它。納達。 – Droidzone