2010-10-18 32 views
0

我有一個簡單的模式對話框,我在我自己的linux服務器上開發,運行php 5.3。腳本(如下所示)在我的服務器上運行良好。但是,我將它移到了我的客戶端的linux服務器上,而不是回顯它顯然應該執行的文本/ html,而是從>(大於)字符開始回顯所有實際的php代碼。有誰知道它爲什麼會回顯實際的代碼?有沒有一個php.ini設置導致這個?或兩種設置中的文件編碼差異?php腳本輸出php代碼,不知道爲什麼

<?php 


$to_email = '[email protected]'; 
$link = $_GET['link']; 
if(!$link){ 
    echo '<p>Have a suggestion?<br />Enter the URL below!</p>'; 
}else if(strlen($link) > 256 || !preg_match('/^(http:\/\/)?subdomain\.somesite\.com\/(somedir\/)?anotherdir\/(.+)/',$link) && !preg_match('/^(http:\/\/)?somedomain2\.com\/somedir2\/(.+)/',$link)){ 
    echo '<p class="error">Whoops, the URL entered doesn\'t <br />match the criteria.</p>'; 
}else{ 
    $link = str_replace("\n.", "\n..", $link); 
    if(!preg_match('/^http:\/\//',$link)){ 
    $link = 'http://'.$link; 
    } 
    mail($to_email, 'New URL Suggestion', "A new URL has been suggested from your site:\n\n".$link,"From: ".$to_email."\r\n"); 
    echo '<p>Thank you for submitting this URL! <br />It should be live within 24 hours.</p>'; 
} 
?> 

結果我的客戶的服務器是:

256 || !preg_match('/^(http:\/\/)?subdomain\.somesite\.com\/(somedir\/)?anotherdir\/(.+)/',$link) && 
!preg_match('/^(http:\/\/)?somedomain2\.com\/somedir2\/(.+)/',$link)){ echo ' 
Whoops, the URL entered doesn\'t 
match the criteria. 

'; }else{ $link = str_replace("\n.", "\n..", $link); 
if(!preg_match('/^http:\/\//',$link)){ $link = 'http://'.$link; } mail($to_email, 
'New URL Suggestion', "A new URL has been suggested from your site:\n\n".$link,"From: 
".$to_email."\r\n"); echo ' 
Thank you for submitting this URL! 
It should be live within 24 hours. 

'; } ?> 
+0

PHP沒有得到解析。你在做什麼擴展? – 2010-10-18 21:09:18

+1

我想這就是你在屏幕上看到的內容......如果你看看代碼,你不知道整個PHP代碼嗎? – greg0ire 2010-10-18 21:11:21

+1

最可能的是整個PHP代碼被髮送,但開放<?被瀏覽器作爲HTML標記進行互動,因此if()中的所有內容都隱藏起來了。查看網頁來源,它將全部在那裏。 – 2010-10-18 21:18:37

回答

3

如果您正在運行的Apache httpd.conf文件可能不必須啓用PHP模塊。

7

聽起來像其他服務器沒有配置爲運行PHP。它在配置中是否有這樣的一行?

AddType application/x-httpd-php .php .html .htm 
+0

你爲什麼要用PHP處理'.html'和'.htm'呢? – NikiC 2010-10-18 21:47:10

+0

哎呀,不打算暗示OP應該這樣做 - 我只是恰好從配置中剪切並粘貼了這行。如果您使用的是框架,這並不是很有用,但對於直接的應用程序來說,它完成了兩件事:1)它隱藏了您在該服務器上使用PHP的事實,因爲這些頁面都顯示爲something.htm而不是某些內容。 PHP。 2)它允許您任意添加PHP到任何文件,而不必擔心重命名它以及所有到它的鏈接。 – 2010-10-18 22:11:34

1

正如在其他錯誤中提到的,這可能是一個服務器配置問題。

如果你使用的是Apache(你可能是),你應該去看看他們的機器上的httpd.conf,它可能位於/etc/apache2/

如果您正在運行PHP作爲一個模塊(默認情況下你是),那麼你需要確保有是有一條線,看起來像這樣:

LoadModule php5_module modules/libphp5.so 

(這是什麼樣子在礦山,路徑/文件名可能會有所不同)

如果使用快速CGI運行PHP,我不知道,因爲我從來沒有使用過它:d

無論哪種方式,你也想做Alex Howansky建議的內容並檢查httpd.conf,看起來像

AddType application/x-httpd-php .php .html .htm 

這配置Apache將指定的擴展名與PHP相關聯。

相關問題