0

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
  • The PHP is not getting parsed. What extension are you running it as? Commented Oct 18, 2010 at 21:09
  • 1
    I guess this is what you see on your screen... if you look at the code, don't you get the whole php code? Commented Oct 18, 2010 at 21:11
  • 1
    Most likely the whole PHP code IS being sent, but the opening <? is being intereprted by the browser as HTML tag, so everything to the <? to > in your if() is hidden. View the page source and it'll all be there. Commented Oct 18, 2010 at 21:18

3 Answers 3

7

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
Sign up to request clarification or add additional context in comments.

2 Comments

Why are you processing .html and .htm with PHP, too?
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.
3

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

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.