Jump to content


Photo

How to print PHP errors and warnings in the web browser?


  • Please log in to reply
4 replies to this topic

#1 dariyoosh

dariyoosh

    Member

  • Members
  • PipPip
  • 11 posts

Posted 18 February 2013 - 03:24 AM

Hello everyone


OS: Fedora Core 17 (x86_64)
Browser: Firefox 18.0
PHP version: 5.4.11
Apache version: 2.2.22


I would like to know whether it is possible to print different kinds of PHP errors (at least parsing errors) in the browser screen. for example
<?php
myVariable = 12
?>
This should give a syntax/parse error because there is not $ before the variable name nor the ";" at the end of the statement.

I modified the file /etc/php.ini by removing comments for the two following options:

. . .
display_errors=On
; Default Value: On
; Development Value: On
; Production Value: Off

; display_startup_errors
; Default Value: Off
; Development Value: On
; Production Value: Off

error_reporting=E_ALL
; Default Value: E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED
; Development Value: E_ALL
; Production Value: E_ALL & ~E_DEPRECATED & ~E_STRICT
. . .

Then I restarted the apache service
# service httpd restart

Yet, I don't see any change, and whenever there is an error, I just have a blank page in the browser.

Any idea? What are the further actions to be taken in order to print errors and warnings on the screen? (Of course, I want to do this only for development/training purpose, here we are not talking about a production environment)


Thanks in advance,

Regards,
Dariyoosh

#2 dariyoosh

dariyoosh

    Member

  • Members
  • PipPip
  • 11 posts

Posted 18 February 2013 - 04:58 AM

Well, it seems that I made a mistake. I edited the file using vim and when I saw
; display_errors=
I thought this was the line to modify and uncomment, but in fact that was just the description section in the "Quick Reference". The actual line to modify is actually further down in the file.

Sorry for my mistake, it works now!


Regards,
Dariyoosh

#3 Jessica

Jessica

    This is not my name.

  • Gurus
  • 8,982 posts
  • LocationDallas, TX
  • Age:26

Posted 18 February 2013 - 10:49 AM

For future reference you can view your actual settings by doing php_info() or an ini_get() so you can check if you changed anything :)
My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.

How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq

Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!

#4 AyKay47

AyKay47

    Sick!

  • Members
  • PipPipPip
  • 3,287 posts
  • LocationEast Coast, U.S.
  • Age:24

Posted 18 February 2013 - 04:17 PM

phpinfo
Hola!
I'm not going to hold your hand and write the code for you - ain't nobody got time for that!

#5 dariyoosh

dariyoosh

    Member

  • Members
  • PipPip
  • 11 posts

Posted 18 February 2013 - 05:05 PM

Thank you very much both of you for your time and your attention to my question.
I will pay attention to phpinfo() for future reference.

For just viewing the PHP directives, I wrote the following which provides the info
<?php
phpinfo(INFO_CONFIGURATION);
?>


Regards,
Dariyoosh




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com