How to see line number instead of 500 error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lostconjugate
Forum Newbie
Posts: 5
Joined: Tue Dec 07, 2010 3:14 pm

How to see line number instead of 500 error

Post by lostconjugate »

Hello,

Does anyone know how to see the line number where the bad syntax is located instead of just getting a 500 error when writing a PHP website? 500 error is not helpful at all in finding my mistakes. Thanks!
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: How to see line number instead of 500 error

Post by Jade »

Are you using Internet Explorer? Some of the older version of IE use something called User Friendly Errors -- which essentially means you see the 500 page instead of the actual error (WTG Microsoft making things harder to debug is your greatest accomplishment).

You can turn it off by going to options > advanced settings. I believe it's at the bottom or near the bottom.
lostconjugate
Forum Newbie
Posts: 5
Joined: Tue Dec 07, 2010 3:14 pm

Re: How to see line number instead of 500 error

Post by lostconjugate »

I tried turning that off and I get the same thing. I also get it in Chrome. I think the user friendly error is one of the 400's, I see it all the time in ASP.NET apps and I can get around it by visiting the website directly on the webserver, that does not work in this case either. The 500 error is "The web page can't be shown"
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: How to see line number instead of 500 error

Post by Jade »

Are you running PHP on a windows machine? Are you sure it's a PHP error you're getting and not something wrong with the URL or DNS? Can you access the file if you don't have an error?
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: How to see line number instead of 500 error

Post by twinedev »

500 is a server error, not something like a runtime/syntax error within PHP. (Ie. the server choked, not PHP)

For Apache: If you have access check your error logs. And on a 500 error, it may not be in a site specific error log, but the primary Apache error log.
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: How to see line number instead of 500 error

Post by Jade »

twinedev wrote:500 is a server error, not something like a runtime/syntax error within PHP.
You can get a 500 server error in IE if you have a syntax error on the page.
lostconjugate
Forum Newbie
Posts: 5
Joined: Tue Dec 07, 2010 3:14 pm

Re: How to see line number instead of 500 error

Post by lostconjugate »

Yea it is everytime I type bad syntax, when I finally find it and fix it the 500 error goes away. In the past I stared at it with my debug stare, it looks something like this :dubious:

Now I have too much code and the debug stare is failing me. My failsafe, which looks like this :banghead: , does not work either. Help!

Oh it is Windows Server 2008, IIS7.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: How to see line number instead of 500 error

Post by califdon »

Temporarily, while debugging, add these 2 lines at the beginning of your PHP code:

Code: Select all

ini_set("display_errors","2");
ERROR_REPORTING(E_ALL);
Remove them when your script is ready to be placed in production (it could reveal helpful information about your environment to a hacker).
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: How to see line number instead of 500 error

Post by McInfo »

califdon wrote:

Code: Select all

ini_set("display_errors","2");
"2"?
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: How to see line number instead of 500 error

Post by califdon »

Oops! Thanks for catching that, McInfo. It should be "1". Not sure how I got that.
User avatar
Apollo
Forum Regular
Posts: 794
Joined: Wed Apr 30, 2008 2:34 am

Re: How to see line number instead of 500 error

Post by Apollo »

Jade wrote:You can get a 500 server error in IE if you have a syntax error on the page.
Then it's still not a PHP error, but just something that is outputted by PHP, which IE happens to choke on (i.e. the page was rendered successfully from PHP's point of view).
lostconjugate
Forum Newbie
Posts: 5
Joined: Tue Dec 07, 2010 3:14 pm

Re: How to see line number instead of 500 error

Post by lostconjugate »

I tried that display errors setting but nto the error_reporting one, so I tried again still 500. I turned on failed request tracing and here is the error it captured:

ErrorCode The operation completed successfully. (0x0)

:crazy:
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: How to see line number instead of 500 error

Post by Benjamin »

McInfo wrote:
califdon wrote:

Code: Select all

ini_set("display_errors","2");
"2"?
When debugging on Windows systems, the number should be set to the number of times the system has been restarted in an attempt to make the issue "go away".
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: How to see line number instead of 500 error

Post by califdon »

Benjamin wrote:
McInfo wrote:
califdon wrote:

Code: Select all

ini_set("display_errors","2");
"2"?
When debugging on Windows systems, the number should be set to the number of times the system has been restarted in an attempt to make the issue "go away".
Awww, Benjamin! LOL :lol:
Post Reply