Hey, I am trying to write a custom assert function that would be used
to forward a user to an error page if the assertion fails. Here is the
definition of this function and an example of its intended usage:
function fm_assert($iser ror)
{
if($iserror)
{
header("Locatio n:http://x.com/errorpage.php") ;
return true;
}
else
return false;
}
//========
// USAGE EXAMPLE
//========
fm_assert(!mysq l_query($sql));
....
header("Locatio n: http://second-page.com");
What should happen here is if there IS an error (assertion fails), then
the user should be forwarded to the error page
(http://x.com/errorpage.php). However, what DOES happen is that the
user actually ends up at http://second-page.com not the error page
(this is happening I guess because the header Location is being
replaced by the 2nd header call).
To prevent this, I added those return statements to the fm_assert
function, and started using it like this:
if(fm_assert(!m ysql_query($sql ))) exit;
This works fine, but it looks ugly. My question is (finally) Is there
some way to make this sleeker so I can call the assert function as just
fm_assert($iser ror) and not have to put the 'if' or the 'exit' in
there?
PS- i tried to move the exit to the fm_assert, but obviously that only
exited the fm_assert function itself, not the page that it was running
in.
Thanks!
to forward a user to an error page if the assertion fails. Here is the
definition of this function and an example of its intended usage:
function fm_assert($iser ror)
{
if($iserror)
{
header("Locatio n:http://x.com/errorpage.php") ;
return true;
}
else
return false;
}
//========
// USAGE EXAMPLE
//========
fm_assert(!mysq l_query($sql));
....
header("Locatio n: http://second-page.com");
What should happen here is if there IS an error (assertion fails), then
the user should be forwarded to the error page
(http://x.com/errorpage.php). However, what DOES happen is that the
user actually ends up at http://second-page.com not the error page
(this is happening I guess because the header Location is being
replaced by the 2nd header call).
To prevent this, I added those return statements to the fm_assert
function, and started using it like this:
if(fm_assert(!m ysql_query($sql ))) exit;
This works fine, but it looks ugly. My question is (finally) Is there
some way to make this sleeker so I can call the assert function as just
fm_assert($iser ror) and not have to put the 'if' or the 'exit' in
there?
PS- i tried to move the exit to the fm_assert, but obviously that only
exited the fm_assert function itself, not the page that it was running
in.
Thanks!
Comment