473,473 Members | 1,874 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

interpreting error messages from include files...

hello,

i am new to PHP programming and wondered if u could help.

lets say i have the following files:

1. error.php: that is routed to for all errors. this page should
display proper and explanatory error messages to the user based on the
parameter provided.
2. errordef.php: has all the error codes and their explanations
"defined" as constants.

now, say if i have 3 different files viz. a.php, b.php and c.php, and
when any error occuring in either these files, i want to route to
error.php for detailed explanation. each a.php, b.php and c.php passes
error code to error.php, but error.php should interpret the code from
the definition file errordef.php!
how can i implement this? any quick help will be appreciated.

Jul 17 '05 #1
10 2292
DH
r6****@gmail.com wrote:
hello,

i am new to PHP programming and wondered if u could help.

lets say i have the following files:

1. error.php: that is routed to for all errors. this page should
display proper and explanatory error messages to the user based on the
parameter provided.
2. errordef.php: has all the error codes and their explanations
"defined" as constants.

now, say if i have 3 different files viz. a.php, b.php and c.php, and
when any error occuring in either these files, i want to route to
error.php for detailed explanation. each a.php, b.php and c.php passes
error code to error.php, but error.php should interpret the code from
the definition file errordef.php!
how can i implement this? any quick help will be appreciated.


If the error occurs in a.php then

@header("Location: ./error.php?id=1");
exit;

And in error.php ...

$id = array_key_exists('id', $_GET) ?
strip_tags(stripslashes(trim($_GET['id']))) : '';

// HTML header here

switch($id)
{

Case 1:
echo '<p>Message 1</p>';
break;

Case 2:
echo '<p>Message 2</p>';
break;

default:
echo '<p>An unknown error occurred</p>';
break;

}; # End switch

// HTML footer
Jul 17 '05 #2
An unknown person wrote:
@header("Location: ./error.php?id=1");


The Location header needs a full URL.

header("Location: http://www.example.com/error.php?id=1");

Regards,
Matthias
Jul 17 '05 #3
r6****@gmail.com wrote:
lets say i have the following files:

1. error.php: that is routed to for all errors.
How is it routed?
2. errordef.php: has all the error codes and their explanations
"defined" as constants.
I'd isolate the explanations inside errordef.php alone. Although
defining constants might make the error treatment faster we hope that
there won't be that many errors as to make it important.
now, say if i have 3 different files viz. a.php, b.php and c.php, and
when any error occuring in either these files, i want to route to
error.php for detailed explanation. each a.php, b.php and c.php passes
error code to error.php, but error.php should interpret the code from
the definition file errordef.php!
how can i implement this? any quick help will be appreciated.


I will call the error code received in error.php as $err_code.

somewhere in error.php include the line

$description = interpret_code($err_code);

where "interpret_code" is a function defined in errordef.php that takes
an error code as an argument and returns a string with the detailed
explanation which you can then use to show the users.
Happy Coding :-)
--
Mail to my "From:" address is readable by all at http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
may bypass my spam filter. If it does, I may reply from another address!
Jul 17 '05 #4
I route to the error.php exactly as mentioned by DH :

header(Location: error.php?err=INVALID_USER);

(BTW, what use is the '@' symbol here? not having the '@' works fine
for me)

I also tried a couple of things and got it working. Heres what I did:

As the error.php will be used for displaying all sorts of errors, I've
made it as a form with action = "GET" so I have $_GET['err'] storing
the error code.

so if i wanted to display the description for the error code
'INVALID_USER' (which has been defined in errordef.php), i simply used:

echo constant($_GET['err']);

It worked! But, I'm not sure if this is a right thing to do! What do
you reckon?

Jul 17 '05 #5
JAS
r6****@gmail.com wrote:
(BTW, what use is the '@' symbol here? not having the '@' works fine
for me)


I prevents an error message being displayed if one should happen. I
always use it with mysql, mail, cookie, and similar functions and trap
errors rather than just letting my app crap out displaying errors that
might compremize the application to the public.

J
Jul 17 '05 #6
On 31 Dec 2004 04:49:05 -0800, <r6****@gmail.com> wrote:
I route to the error.php exactly as mentioned by DH :

header(Location: error.php?err=INVALID_USER);
must be: header('Location:
'.$_SERVER['HTTP_HOST'].'/error.php?err=INVALID_USER');

(BTW, what use is the '@' symbol here? not having the '@' works fine
for me)
@ disables error reporting for certain command/expression.

echo constant($_GET['err']);


using unverified data from external source is a bit unwise.

maybe put errors in an array
$errors = array(
'INVALID_USER'=>'whatever',
'ETC'=>'etc',
);

and use fail-safe
echo isset($errors[$_GET['err']])?$errors[$_GET['err']]:'Unknown Error';
--
* html {redirect-to: url(http://browsehappy.pl);}
Jul 17 '05 #7
JAS wrote:
r6****@gmail.com wrote:
(BTW, what use is the '@' symbol here? not having the '@' works fine
for me)

I prevents an error message being displayed if one should happen. I
always use it with mysql, mail, cookie, and similar functions and trap
errors rather than just letting my app crap out displaying errors that
might compremize the application to the public.

There is another way to avoid showing errors to the public, and I think
it's better:

<quote src="http://es2.php.net/manual/en/security.errors.php">

A better option is not to disable error reporting, but just not showing
them, and let them log to a file.

For example, set in your php.ini file:
log_errors on
display_errors off
error_log /var/log/php_errors

</quote>
This way you can still see the errors, not in the client window but
rather in a private file local to the server. When there's need to
debug, you see the real errors as they happened , instead of having to
edit the source code to let them show and then reproduce them.

Obviously, trapping errors when they happen is the best thing to do, but
it's very difficult to catch 'em all.
Jul 17 '05 #8
JAS
Dani CS wrote:
JAS wrote:
r6****@gmail.com wrote:
(BTW, what use is the '@' symbol here? not having the '@' works fine
for me)


I prevents an error message being displayed if one should happen. I
always use it with mysql, mail, cookie, and similar functions and trap
errors rather than just letting my app crap out displaying errors that
might compremize the application to the public.


There is another way to avoid showing errors to the public, and I think
it's better:

<quote src="http://es2.php.net/manual/en/security.errors.php">

A better option is not to disable error reporting, but just not showing
them, and let them log to a file.

For example, set in your php.ini file:
log_errors on
display_errors off
error_log /var/log/php_errors

</quote>
This way you can still see the errors, not in the client window but
rather in a private file local to the server. When there's need to
debug, you see the real errors as they happened , instead of having to
edit the source code to let them show and then reproduce them.

Obviously, trapping errors when they happen is the best thing to do, but
it's very difficult to catch 'em all.


Yah I totally agree -- I just use them for those few that I are most
likely to occur and are easily trappable @mysql_connect .... or die ...

J
Jul 17 '05 #9
Hi,

why do you not set up an error handling function with
set_error_handler('myErrorHandlingFunctionName') ?

The error handling function typically has parameters ($level, $message,
$filePath, $lineNumber). Trom the error handling function you can log
the error.
if ($level & error_reporting()) {
You can redirect the browser from the error handling function by
outputting the following javascript:
<script>
document.location.href=error.php
</script>;
}
(This usually works better then header("Location: ./error.php");
exit; because it is not limited to before any output has been done)

Greetings,

Henk Verhoeven,
www.phpPeanuts.org.

r6****@gmail.com wrote:
hello,

i am new to PHP programming and wondered if u could help.

lets say i have the following files:

1. error.php: that is routed to for all errors. this page should
display proper and explanatory error messages to the user based on the
parameter provided.
2. errordef.php: has all the error codes and their explanations
"defined" as constants.

now, say if i have 3 different files viz. a.php, b.php and c.php, and
when any error occuring in either these files, i want to route to
error.php for detailed explanation. each a.php, b.php and c.php passes
error code to error.php, but error.php should interpret the code from
the definition file errordef.php!
how can i implement this? any quick help will be appreciated.

Jul 17 '05 #10
Henk Verhoeven wrote:
You can redirect the browser from the error handling function by
outputting the following javascript:
<script>
document.location.href=error.php
</script>;
}
(This usually works better then header("Location: ./error.php");
exit; because it is not limited to before any output has been done)


While it is true that your proposed javascript code is not affected by
the "headers already sent" syndrome, it creates some serious problems
for the user. Read these:

- http://www.w3.org/QA/Tips/reback
- http://www.useit.com/alertbox/990530.html (the first one)

<snip>
Jul 17 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Raja Koduru | last post by:
Hello everybody, I am not yet fully comfortable with understanding c++ warnings/error messages. Very recently I have updated my IDE to VC++7.0 (MS.Net 7.0-Enterprise architect) from vc++6....
8
by: Vavel | last post by:
Hi all! I used google, but I found nothing. I have got smiple code: #include <sql.h> int main() { } when I compiled this in Borland C++ 5.5.1 for Win32 Copyright (c) 1993,
7
by: tyler_durden | last post by:
thanks a lot for all your help..I'm really appreciated... with all the help I've been getting in forums I've been able to continue my program and it's almost done, but I'm having a big problem that...
2
by: Qiao Yun | last post by:
I used vc++.net (visual studio .net ) to open a project which can work well in vc++6.0. I succeeded in compiling the project in vc++.net in release mode . But when I tried to compile the project...
7
by: Greg Buchholz | last post by:
I'm wondering if anyone has advice for figuring out error messages produced by g++. The programs below works fine, until I uncomment out the two "transform" lines. Then it points me to line 24...
8
by: Brian Tkatch | last post by:
Server: DB2/SUN 8.1.6 Client: DB2 Connect Personal Edition (No 11) <URL:ftp://ftp.software.ibm.com/ps/products/db2/fixes2/english-us/db2winIA32v8/fixpak/FP11_WR21365/FP11_WR21365_CONPE.exe> ...
1
by: misu101 | last post by:
Hi, I have a VS 6 project and I am trying to compile it using VS 2005. My program has the atlbase.h include which seems to trigger the errors. It used to compile OK using VS 6. The include...
2
by: akhilesh.noida | last post by:
I am trying to compile glibc-2.5 for ARM based board. But I am getting errors while configuring it. Please check and give your inputs for resolving this. configure command : $...
3
by: imaloner | last post by:
I am posting two threads because I have two different problems, but both have the same background information. Common Background Information: I am trying to rebuild code for a working,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.