Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Why continiue the program after return false in this example?

1 view
Skip to first unread message

Karl-Arne Gjersøyen

unread,
Sep 4, 2010, 6:47:56 AM9/4/10
to
<?php
function valid_email_address(){
$mail = '';
}
if (strlen($mail) < 8){
echo "<p>Please fill in your email address. Need at least 8
characters</p>";
return false;
}
?>

How can I do as the program stop running if error is detected? Use
exit() instead?

Karl

Jerry Stuckle

unread,
Sep 4, 2010, 9:14:30 AM9/4/10
to

exit() will terminate processing. Nothing here will stop the program.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstu...@attglobal.net
==================

]-[oRus

unread,
Sep 4, 2010, 10:08:31 AM9/4/10
to
Op 04-09-2010 12:47, Karl-Arne Gjersøyen schreef:

Aside from the main question: why do you think you need at least 8 chrs
in a address? x...@hp.nl can be a valid address....

--

]-[oRus
www.smallsystemservice.nl

J.O. Aho

unread,
Sep 4, 2010, 12:45:06 PM9/4/10
to

Why do you want to "stop"? Isn't it better that you validate all input first
and then tell the user all the faults, instead of "fixing" things, they will
get yet another error message.

exit() is a bad way to terminate the execution, it will cause a lot of
aesthetic troubles (you will still make your error output look nice as the
rest of the site) and you can't validate all data, only one at the time if
there are more than one faulty and you may expose more to the end user than
you will (example exit(mysql_error()); is a bad thing to do).

As others already pointed out, the less than 8 characters for email address
will filter out quite many valid ones, most of my email addresses on one of my
domains would not be validated this way and it seems like you will have even
more false positives tooif you only use the length as a way to check. I would
have used a regular expression check, that way I don't have to check for a
minimum email length of 5 characters.


Read this for further information: http://www.linuxjournal.com/article/9585

--

//Aho

MG

unread,
Sep 4, 2010, 3:35:10 PM9/4/10
to
> Aside from the main question: why do you think you need at least 8 chrs in
> a address? x...@hp.nl can be a valid address....

I was playing around with
filter_var($var,FILTER_VALIDATE_EMAIL)
a@b.c validates

It is probably better to let invalid addresses go through than to filter out
valid ones

MG


0 new messages