PHP printing on command prompt / terminal but not on browser

Viewed 43

I had been asked in an interview for PHP. In a PHP file index.php, there are 4 lines of code:

  1. Line 1 Takes input from user
  2. Line 2 Encrypts the User input
  3. Line 3 Decrypts the the Encrypted User input of line 2
  4. Line 4 Prints the Decrypted content of line 3

On executing this file via command prompt/terminal like php index.php, Original User input of line 1 gets printed/displayed by Line 4 in the command prompt/terminal but when opened/executed in browser the same code did not display anything. What could be the reason ?

Please explain if anyone knows, would be helpful in future interviews if asked.

1 Answers

This could happen if the user input is a valid HTML tag, e.g. something as simple as

<b>

Or any other valid tag.

This value would still be output by the PHP program but the browser would see it as HTML and treat it as instructions rather than displaying it directly in the web page. You'd still be able to see it via the element inspector in the browser's Developer Tools.

Related