0

I have a php script like this :

<?php
$confirmationCode = trim($_GET['confcode']);
$_SERVER['REMOTE_ADDR'] = 'xxx.xxx.xxx.xxx';
$emailLogId = 1;
if ($_SERVER['REMOTE_ADDR']=='xxx.xxx.xxx.xxx') {
//   print '<pre>' .'xxxxx' . $emailLogId . '###';  //exit ;    
}
if( is_numeric($emailLogId)) {
if ($_SERVER['REMOTE_ADDR']=='xxx.xxx.xxx.xxx') {
// print '<pre>yyy' . $_GET['emaillog_id'] . 'yyyxxxxxx ' . $emailLogId;  print_r             ($row) ; exit ;   
}
//$osDB->query('UPDATE ! SET clicktime=? WHERE id=?', array('email_logs', time(),   $emailLogId));
} else {
if ($_SERVER['REMOTE_ADDR']=='xxx.xxx.xxx.xxx') {
//   print '<pre>zzz' . $_GET['emaillog_id'] . 'yyyxxxxxx ' . $emailLogId;  print_r ($row) ; exit ;     
}
}
?>

It is running on my server. Actually some people are complaining that they are seeing the source code of this script( pasted below ) on their browser and they send me snap shot of this issue:

 ' .'xxxxx' . $emailLogId . '###';  //exit ;    
}
 if( is_numeric($emailLogId)) {
 if ($_SERVER['REMOTE_ADDR']=='xxx.xxx.xxx.xxx') {
// print '<pre>yyy' . $_GET['emaillog_id'] . 'yyyxxxxxx ' . $emailLogId;  print_r ($row) ; exit ;   
}
//$osDB->query('UPDATE ! SET clicktime=? WHERE id=?', array('email_logs', time(), $emailLogId));
 } else {
if ($_SERVER['REMOTE_ADDR']=='xxx.xxx.xxx.xxx') {
 //  print '<pre>zzz' . $_GET['emaillog_id'] . 'yyyxxxxxx ' . $emailLogId;  print_r ($row) ; exit ;     
}
 }
?>

Actually I am really confused because I am not able to reproduce this problem, but 3-4 people are complaining about same the thing.

Do you have any idea what is the issue?

3
  • Have you verified, that those guys have php up an running? Commented Aug 27, 2012 at 6:35
  • @Tim, those guy doesnt need PHP running in their machine. Their browser is just outputing the php code Its likely your apache is behaving weirdly, sometimes it parses php and sometimes it doesnot. Check with the hosting server, contact them if there is any misconfiguration in apache Commented Aug 27, 2012 at 6:37
  • Does everyone access it from your server? Commented Aug 27, 2012 at 6:40

2 Answers 2

2

Yes, similar thing happened with me too.

2 things:

. Apache configuration.

Make sure php engine is ON. If you cannot access your apache configuration file then, add this in your .htaccess:

php_flag engine on

. CDN.

If you are using any Cloud Distribution Network, it is time for you to ask them to purge your existing cache and re-load the new one.

Browser will display PHP source code ONLY AND ONLY if apache configuration is going wrong.

Hope that helps.

EDIT:

After reading Sabin's comment, I gave a second look at the code.

Problem is, he has ASSIGNED the value to $_SERVER['REMOTE_ADDR'] (line 3)

Here is how it should be:

<?php
$confirmationCode = trim($_GET['confcode']);
$ip = 'xxx.xxx.xxx.xxx';
$emailLogId = 1;

//Whatever conditions.
if ($_SERVER['REMOTE_ADDR'] == 'xxx.xxx.xxx.xxx') {
//   print '<pre>' .'xxxxx' . $emailLogId . '###';  exit ;    
}
if( is_numeric($emailLogId)) {
if ($_SERVER['REMOTE_ADDR'] == 'xxx.xxx.xxx.xxx') {
// print '<pre>yyy' . $_GET['emaillog_id'] . 'yyyxxxxxx ' . $emailLogId;  print_r             ($row) ; exit ;   
}
//$osDB->query('UPDATE ! SET clicktime=? WHERE id=?', array('email_logs', time(),   $emailLogId));
} else {
if ($_SERVER['REMOTE_ADDR']=='xxx.xxx.xxx.xxx') {
//   print '<pre>zzz' . $_GET['emaillog_id'] . 'yyyxxxxxx ' . $emailLogId;  print_r ($row) ; exit ;     
}
}
?>

However, echo-ing the source code cannot be due to this. I would ask you to put FULL FILE so that we could see if you are missing a closing single quote!

Sign up to request clarification or add additional context in comments.

9 Comments

Exactly my thought. Seems more of an configuration issue. Also the OP must be testing on his machine which is already setup and hence he does not get the error!!
+1 The same happened with me 2 years ago. Trust me, it was a nightmare at that time!
but one question is here, THe apache parses first 5 line correctly, the php code is outputted only right after <pre> tag is used in comment. It should have outputted whole code right from <? if its apache misconfiguration
@Sabin : Have you tried it at your end. May be the users are giving you just a piece of the code that gets displayed
@ClydeLobo, I m not getting error in my end. I dont know how his users got it. And I m still wondering if its Apache misconfiguration in his server, then why all of the code is not showing in browser [As The post owner pasted the code that is being outputted in the browser, which starts write after <pre>], and its no way browser parses the comments.
|
1

It sounds like PHP is not working at all. The only reason you are not seeing the first part, is because your browsers is parsing it as if it were an HTML tag.

And Please try to print phpinfo() once,

please check for the below link, for more details

PHP code displayed in browser

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.