2010-10-18 61 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相关联。

相关问题