Home > Archive > PHP Programming > June 2007 > error-logs() bug ??
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
error-logs() bug ??
|
|
| yaaros@gmail.com 2007-06-26, 7:02 pm |
| Hello !! I have a problem with error_logs. The problem is in this
code:
$id_tmp = $_REQUEST["id"];
if(!isset($id_tmp) && empty($id_tmp)){
invalidArgs();
echo "buug";
}
I'd like to check if the variable id is passed by GET method to the
script. If not, function invalidArgs() will start.
In function invalidArgs() I thrown exception InvalidArgsException. I
set a handler for whole script to manage exceptions using
set_exception_handler(); function. I write, by error_log, errors to
file and show warning page that the parameter id isn't pass through.
And the problem is that when I open this page in www browser IE6 and
put correct parameter id everything is ok, the page that suppose to is
showing but in file where errors are written (by error_logs), are
appeared errors of InvalidArgsException ?? That's really weird
because the script doesn't suppose to get into if-block and start
function invalidArgs(). What is wrong, why error_log writes an errors
that doesn't suppose to ?? Everything work correct, the page and the
rest of the script acts like it gets the id parameter from GET
methods, but there is entry in error_log file ??
| |
| Willem Bogaerts 2007-06-26, 7:02 pm |
| > $id_tmp = $_REQUEST["id"];
This fails if there is no index "id", that is, if there is no id field sent.
> if(!isset($id_tmp) && empty($id_tmp)){
> invalidArgs();
> echo "buug";
> }
This part will not be reached, because the code fails before this block.
> ..., the page that suppose to is
> showing but in file where errors are written (by error_logs), are
> appeared errors of InvalidArgsException ?? That's really weird
> because the script doesn't suppose to get into if-block and start
> function invalidArgs().
Best regards,
--
Willem Bogaerts
Application smith
Kratz B.V.
http://www.kratz.nl/
| |
| Captain Paralytic 2007-06-26, 7:02 pm |
| On 26 Jun, 15:13, yaa...@gmail.com wrote:
> Hello !! I have a problem with error_logs. The problem is in this
> code:
>
> $id_tmp = $_REQUEST["id"];
> if(!isset($id_tmp) && empty($id_tmp)){
> invalidArgs();
> echo "buug";
>
> }
>
> I'd like to check if the variable id is passed by GET method to the
> script. If not, function invalidArgs() will start.
> In function invalidArgs() I thrown exception InvalidArgsException. I
> set a handler for whole script to manage exceptions using
> set_exception_handler(); function. I write, by error_log, errors to
> file and show warning page that the parameter id isn't pass through.
>
> And the problem is that when I open this page in www browser IE6 and
> put correct parameter id everything is ok, the page that suppose to is
> showing but in file where errors are written (by error_logs), are
> appeared errors of InvalidArgsException ?? That's really weird
> because the script doesn't suppose to get into if-block and start
> function invalidArgs(). What is wrong, why error_log writes an errors
> that doesn't suppose to ?? Everything work correct, the page and the
> rest of the script acts like it gets the id parameter from GET
> methods, but there is entry in error_log file ??
Try
if(!isset($_REQUEST["id"]) || empty($_REQUEST["id"])){
invalidArgs();
echo "buug";
}
| |
| yaaros@gmail.com 2007-06-26, 7:02 pm |
| On 26 Cze, 16:16, Willem Bogaerts
<w.bogae...@kratz.maardanzonderditstuk.nl> wrote:
>
> This fails if there is no index "id", that is, if there is no id field sent.
>
>
> This part will not be reached, because the code fails before this block.
>
>
> Best regards,
> --
> Willem Bogaerts
>
> Application smith
> Kratz B.V.http://www.kratz.nl/
I don't understand. I know that when the id parameter won't be send
the code fails. But when I send this field and everything is ok
watching on www page, but in error_log file there is an entry that the
InvalidArgsException was throwed, what is untrue because in that case
I couldn't see right www page on my browser, that means something is
wrong. And I don't know what :( ? Is anyone had that kind of problem ??
| |
| yaaros@gmail.com 2007-06-26, 7:02 pm |
| On 26 Cze, 16:24, Captain Paralytic <paul_laut...@yahoo.com> wrote:
> On 26 Jun, 15:13, yaa...@gmail.com wrote:
>
>
>
>
>
>
>
>
> Try
>
> if(!isset($_REQUEST["id"]) || empty($_REQUEST["id"])){
> invalidArgs();
> echo "buug";
>
> }
It doesn't work. Still writes me an Exceptions error in errol_log
file :(
| |
| Michael Fesser 2007-06-26, 7:02 pm |
| ..oO(yaaros@gmail.com)
>Hello !! I have a problem with error_logs. The problem is in this
>code:
>
>$id_tmp = $_REQUEST["id"];
>if(!isset($id_tmp) && empty($id_tmp)){
> invalidArgs();
> echo "buug";
>}
>
>I'd like to check if the variable id is passed by GET method to the
>script.
If you're expecting a GET variable then use the $_GET array. The
$_REQUEST array contains values from three(!) different sources and
should only be used in very special cases.
Additionally you should set error_reporting to E_ALL in your php.ini.
The first line from the code above will cause a notice if no 'id'
parameter was submitted.
It should be something like:
if (!isset($_GET['id'])) {
invalidArgs();
echo "buug";
}
If you also want to check for empty parameters add an OR condition:
if (!isset($_GET['id']) || empty($_GET['id'])) {
invalidArgs();
echo "buug";
}
Micha
| |
| Michael Fesser 2007-06-26, 7:02 pm |
| ..oO(yaaros@gmail.com)
>It doesn't work. Still writes me an Exceptions error in errol_log
>file :(
This can't happen with just the little snippet you posted. It's most
likely something in the rest of your code.
Do you always get the "buug" output even if there shouldn't be an error
message? Is InvalidArgs() called somewhere else in the script? Is the
exception handler working correctly? Are you sure the error message is a
recent one (do you log a timestamp)?
Just some guesses.
Micha
| |
| yaaros@gmail.com 2007-06-26, 7:02 pm |
| On 26 Cze, 16:38, Michael Fesser <neti...@gmx.de> wrote:
> .oO(yaa...@gmail.com)
>
>
> This can't happen with just the little snippet you posted. It's most
> likely something in the rest of your code.
>
> Do you always get the "buug" output even if there shouldn't be an error
> message?
No the thing is that I haven't got the "buug" output when shouldn't be
an error.
> Is InvalidArgs() called somewhere else in the script?
No there is only one place in that script where I call it. I'm sure
that it is throwing exactly this exception because with the exception
message I send current date and string that is never repetead in code.
>Is the exception handler working correctly?
Habdler seems to work ok, because when I don't pass the id parameter
it shows me error www page like it suppose to.
>Are you sure the error message is a recent one (do you log a timestamp)?
Yes I put the date in message that is written in error_log file and
its recent.
>
> Just some guesses.
>
> Micha
Thanks but it still doesn't help me :(
| |
| Michael Fesser 2007-06-26, 7:02 pm |
| ..oO(yaaros@gmail.com)
>On 26 Cze, 16:38, Michael Fesser <neti...@gmx.de> wrote:
>
>No the thing is that I haven't got the "buug" output when shouldn't be
>an error.
So you get an error message in your logfile, but no "buug" output? Maybe
a backtrace can shed some light on it. In my own exception handler I
call the exception's getTraceAsString() method and write the output to
the error log. This helps me to figure out where exactly the error
occured and what method calls led to it.
Apart from that the only idea would be to post (or upload to a website)
a _complete_ example code that causes the error. Of course this test
case should be as short as possible.
Micha
| |
| Jerry Stuckle 2007-06-26, 9:59 pm |
| yaaros@gmail.com wrote:
> Hello !! I have a problem with error_logs. The problem is in this
> code:
>
> $id_tmp = $_REQUEST["id"];
> if(!isset($id_tmp) && empty($id_tmp)){
> invalidArgs();
> echo "buug";
> }
>
> I'd like to check if the variable id is passed by GET method to the
> script. If not, function invalidArgs() will start.
> In function invalidArgs() I thrown exception InvalidArgsException. I
> set a handler for whole script to manage exceptions using
> set_exception_handler(); function. I write, by error_log, errors to
> file and show warning page that the parameter id isn't pass through.
>
> And the problem is that when I open this page in www browser IE6 and
> put correct parameter id everything is ok, the page that suppose to is
> showing but in file where errors are written (by error_logs), are
> appeared errors of InvalidArgsException ?? That's really weird
> because the script doesn't suppose to get into if-block and start
> function invalidArgs(). What is wrong, why error_log writes an errors
> that doesn't suppose to ?? Everything work correct, the page and the
> rest of the script acts like it gets the id parameter from GET
> methods, but there is entry in error_log file ??
>
That is correct.
$id_tmp = $_REQUEST["id"];
will log a notice if $_REQUEST["id"] is not set. You should be checking
it directly instead of setting $id_tmp.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
| |
| yaaros@gmail.com 2007-06-27, 8:00 am |
| I found the reason why is errors written in log file but I still don't
understand that :).
Before in the code I have got an img tag which was written like that:
<img src="?" alt="" width=1 height=1>
It have bad src attribute and this causes somehow my problems. When I
delete this img tag log file become empty after refreshing pages.
Intresting huh ??
I have no idea why this tag causes that the first trown exceptions in
code was written in log file but it's true.
Maybe somena could explain me that ??
Thanks for yoours answers
| |
| Jerry Stuckle 2007-06-27, 7:01 pm |
| yaaros@gmail.com wrote:
> I found the reason why is errors written in log file but I still don't
> understand that :).
> Before in the code I have got an img tag which was written like that:
>
> <img src="?" alt="" width=1 height=1>
>
> It have bad src attribute and this causes somehow my problems. When I
> delete this img tag log file become empty after refreshing pages.
> Intresting huh ??
>
> I have no idea why this tag causes that the first trown exceptions in
> code was written in log file but it's true.
> Maybe somena could explain me that ??
>
> Thanks for yoours answers
>
This is HTML code and wouldn't cause a PHP exception. It would,
however, cause an error in the apache error log relating to the invalid
image filename.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
| |
| Michael Fesser 2007-06-27, 7:01 pm |
| ..oO(yaaros@gmail.com)
>I found the reason why is errors written in log file but I still don't
>understand that :).
>Before in the code I have got an img tag which was written like that:
>
><img src="?" alt="" width=1 height=1>
>
>It have bad src attribute and this causes somehow my problems. When I
>delete this img tag log file become empty after refreshing pages.
>Intresting huh ??
Logical. The URL in the 'src' attribute is empty. When resolving that,
the browser starts with the base URL, which is usually the one of the
current document unless you use a 'base' element. So in fact requesting
the image leads to a second request of the same page, but with an empty
query string -> exception.
You could also write the content of $_SERVER['REQUEST_URI'] to your
error log to see that.
Micha
| |
| yaaros@gmail.com 2007-06-28, 3:59 am |
| That's right Michael. This img tag with wrong src attribute causes the
second request with invalid args exception. Silly mistake but it takes
some time to find it ;). Anyway thanks everyone for help.
|
|
|
|
|