473,397 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Log and Error/Info Message class

Hello,

I would like to develop an independent class that will store Messages,
Warnings and Errors.
Messages and Warnings Will be displayed to the user.
Errors will be loged in a database or/and emailed to the admin.

The part that Interests me at the moment is the messages that will be
displayed to the user.

What is the best practice of doing such a thing ?
Is it correct to store them in a $_SESSION ?

The reason I would like to do that class is because at the moment I
execute a Database Query and then I want to redirect and then display
the message: Succesfull or Not. Otherwise I'll get headers already sent.

Do you know how I can overcome this problem and if what I am thinking is
correct ?

Thanks
Angelos.
Dec 15 '05 #1
6 1971
There is already a very robust logging class
http://pear.php.net/package/Log/ that I find very useful.

Other than that I am not sure what you are looking for, do you want to
show errors that php generates? Do you want to inform the user if a
query was successful or not? What are these errors that are being
generated?

Dec 15 '05 #2
> Other than that I am not sure what you are looking for, do you want to
show errors that php generates? Do you want to inform the user if a
query was successful or not? What are these errors that are being
generated?

What I want is to inform users that
- a query was succesfully competed
- the login details they entered were wrong
- that an image was uploaded succesfully
.....
- And all this usefull messages that a script can generate.

Ofcourse I am able to do that really easy but if I want to redirect at
the same time then I need to store that message somewhere and after the
redirection, display it.
Also I need to display all the messages in a specific div inside my page.
That means that my index.php page has a div like that:
<div id="status">
$log = new $log();
$log->displayStoredMessage();
</div>

And my class that handles the queries look like that:

$result = mysql_query("SELECT * FROM cms_users WHERE cms_user_email =
'".$email."' AND cms_user_passwd = '".$password."'") or die(mysql_error());
$num_rows = mysql_num_rows($result);
....
if($num_rows == 1)
return true;
else
{
$log=new log();
$log->Log('Message','Invalid Login, please make sure you enter your
Email and Password.<br>If you forgot your password, enter your email and
hit the forgot password button.');
}
Dec 15 '05 #3
There are a few things to consider. From your story, I understand that
you just want a message passed to the user. You could store it in the
session, but I see no need. A log is more useful if you want to store
the message to be seen by the admin at a later time.

If you want to display the message, I understand that the redirection
cannot take place. So no redirection headers will be sent if you want to
show the user the message. That is why I think there is no need to store
anything if you only want to show it to the user. If you want to show it
to the admin, it is off course wise to store or e-mail it.

If you use a META tag to do the redirection, you can give a time to wait
before the redirection, so you can redirect and pass a message without
much difficult programming.

I do not know what you want exactly, but if it is your own page you
redirect to, you can consider posting to the same page that contained
your form and show the form if no valid input was found, with messages
if invalid input was present, and the results if the input was valid.

Best regards

Angelos wrote:
Other than that I am not sure what you are looking for, do you want to
show errors that php generates? Do you want to inform the user if a
query was successful or not? What are these errors that are being
generated?

What I want is to inform users that
- a query was succesfully competed
- the login details they entered were wrong
- that an image was uploaded succesfully
....
- And all this usefull messages that a script can generate.

Ofcourse I am able to do that really easy but if I want to redirect at
the same time then I need to store that message somewhere and after the
redirection, display it.
Also I need to display all the messages in a specific div inside my page.
That means that my index.php page has a div like that:
<div id="status">
$log = new $log();
$log->displayStoredMessage();
</div>

And my class that handles the queries look like that:

$result = mysql_query("SELECT * FROM cms_users WHERE cms_user_email =
'".$email."' AND cms_user_passwd = '".$password."'") or die(mysql_error());
$num_rows = mysql_num_rows($result);
...
if($num_rows == 1)
return true;
else
{
$log=new log();
$log->Log('Message','Invalid Login, please make sure you
enter your Email and Password.<br>If you forgot your
password, enter your email and hit the forgot password button.');
}

Dec 15 '05 #4
Just one thing. Look at what happens if the user types his email as:
' OR 1=1 LIMIT 1;-- ha**@haha.com

I hope you use some addslashes function before passing it to the database.

....
And my class that handles the queries look like that:

$result = mysql_query("SELECT * FROM cms_users WHERE cms_user_email =
'".$email."' AND cms_user_passwd = '".$password."'") or die(mysql_error());
$num_rows = mysql_num_rows($result);
...
if($num_rows == 1)
return true;
else
{
$log=new log();
$log->Log('Message','Invalid Login, please make sure you
enter your Email and Password.<br>If you forgot your
password, enter your email and hit the forgot password button.');
}

Dec 15 '05 #5
Dikkie Dik wrote:
Just one thing. Look at what happens if the user types his email as:
' OR 1=1 LIMIT 1;-- ha**@haha.com

I hope you use some addslashes function before passing it to the database.


I do not understand what you mean by that..\0\0\0What exactly if he types ?
I don't use any addslashes, the only think I do is I check if the e-mail
that the user enters is valid (valid syntax
Dec 16 '05 #6
I hate to disappoint you, but the address:
' OR 1=1 LIMIT 1;-- ha**@haha.com

IS a valid e-mail address. I tried it. Replaced haha.com with my own
subdomain and I had absolutely no problem sending and recieving a
message to that address.

But you e-mail validation will probably filter it out. If it doesn't, it
gets part of your SQL statement, which then reads:

SELECT * FROM cms_users WHERE cms_user_email = '' OR 1=1 LIMIT 1;--
ha**@haha.com' AND cms_user_passwd = ''

Which just returns the first user from the table without any error
messages. (cms_user_email = '' OR 1=1 is always TRUE and -- is a start
of a comment and switches the rest off for parsing. I added the LIMIT
clause to return exactly one record. From your code, I think you may
have a problem when a user registers twice, as there will be 2 records
found with his address)

When I think about it, I could probably better use the password for
that. And I don't even have to know the database structure, as I will
make the site simply tell me. First try:
User: jo**@someplace.com
Password 'BigUglyError

(Notice the single quote) If you dont filter out illegal passwords as
well, your page now "dies" with a detailed error message containing the
table names and the full WHERE clause.

Now I can try a password like:
' UNION SELECT * FROM cms_users LIMIT 1--
which basically does the same.

Angelos Devletoglou wrote:
Dikkie Dik wrote:
Just one thing. Look at what happens if the user types his email as:
' OR 1=1 LIMIT 1;-- ha**@haha.com

I hope you use some addslashes function before passing it to the
database.

I do not understand what you mean by that.. What exactly if he types ?
I don't use any addslashes, the only think I do is I check if the e-mail
that the user enters is valid (valid syntax

Dec 17 '05 #7

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

Similar topics

0
by: besaar | last post by:
i got the current project that got the serial no.of a hard disk for software protection but i got an error,if u solve it send me,thanx alllllll. 1.file1 Option Strict On Option Explicit On...
7
by: Steve Jorgensen | last post by:
Here is some code to generate code for raising and getting information about custom errors in an application. Executing the GenerateXyzErrDefs procedure generates the code. <tblXyzError>...
7
by: Philip Wagenaar | last post by:
I use a class to manage tiff's (written by someone else) to splitt multipage tiffs. However, when I run it, it fails, for other people it seems work ok. The method in the class is :public...
1
by: Red | last post by:
I am taking a c++ course. I have a simple program that just wont compile and I cant seem to figure out why. If I compile the class file without referencing it in the int main() it will compile but...
4
by: Larry Tate | last post by:
I am wanting to get those cool html error pages that ms produces when I hit an error in asp.net. For instance, when I get a compilation error I get an html error page that shows me the ...
7
by: p | last post by:
WE had a Crystal 8 WebApp using vs 2002 which we upgraded to VS2003. I also have Crystal 9 pro on my development machine. The web app runs fine on my dev machine but am having problems deploying....
2
by: Phillip Galey | last post by:
I have an object called Place which contains only string properties and has the <Serializable()> flag before the class name declaration. I also have a collection object called Places, which is...
3
by: Gary Wessle | last post by:
Hi I tried so long, so many ways to find out why this code is not compiling, I appreciate any help with it, thank you ****************************************************************...
0
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
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,...

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.