tags:

views:

75

answers:

3

I have a simple modal dialog that I developed on my own linux server, running php 5.3. The script (shown below) runs fine on my server. However, I moved it to my client's linux server and instead of echoing the text/html that it apparently is supposed to do, it echos ALL the actual php code from the > (greater than) character on. Does anyone know why it would echo the actual code? Is there a php.ini setting that causes this? or file encoding difference in the two setups?

<?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>';
 }
?>

The result on my client's server is:

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.

'; } ?>
+3  A: 

If you are running apache your httpd.conf file probably doesnt have the php module enabled.

philip
+7  A: 

Sounds like the other server isn't configured to run PHP. Does it have a line like this in the config?

AddType application/x-httpd-php .php .html .htm
Alex Howansky
Why are you processing `.html` and `.htm` with PHP, too?
nikic
Whoops, didn't intend to imply the OP should do that -- I just happened to cut and paste this line from a config where I have this set. It's not very useful if you're using a framework, but for straight apps, it accomplishes two things: 1) It hides the fact you're using PHP on that server, because the pages all appear as something.htm instead of something.php. 2) It allows you to arbitrarily add PHP to any file without worrying about renaming it and all the links to it.
Alex Howansky
+1  A: 

As mentioned in the other errors, this is probably a server configuration problem.

If you are using Apache (you probably are), you should go take a look at httpd.conf on their machine, which is probably located in /etc/apache2/.

If you are running PHP as a module (by default you are), then you need to make sure that there is a line in it that looks like this:

LoadModule php5_module modules/libphp5.so

(That's what it looks like on mine, the path/filename may be different)

If you are running PHP with Fast-CGI, I'm not sure, as I've never used it :D

Either way, you also want to do what @Alex Howansky suggests and check httpd.conf for a line that looks like

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

This configures Apache to associate the specified extensions with PHP.

Austin Hyde