Confusion about order of procedures

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Bigun
Forum Contributor
Posts: 237
Joined: Tue Jun 13, 2006 10:50 am

Confusion about order of procedures

Post by Bigun »

I'm making some code to validate the format of an e-mail address and also a captcha check.

Code: Select all

if ($username != "" || $fname != "" || $lname != "" || $email != "" || $password != "" || $vpassword != "" || $legaleagree != "") {
        //captcha procedure
        include "./captcha/audit.php";
        //e-mail validation procedure
        include "validate.php";

        $failed = "no";
        //e-mail check
        if ($email != "") {
                if (validate_email($email)) {
                } else  {
                        echo "<center><font color=red><b>Please type in a valid e-mail address</b></font></center>";
                        $failed = "yes";
                }
        }
        //captcha check
        if (audit() && $failed != "yes") {
        } else {
                echo "<center><font color=red><b>Please type in the correct text from the picture into the box below</b></font></cent$
                $failed = "yes";
        }
For some reason, with the e-mail format check left in the code, the captcha always returns false.

If I comment out the e-mail check, the captcha portion works properly.

I can post the modules if the info is needed.
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Re: Confusion about order of procedures

Post by a94060 »

Bigun wrote:I'm making some code to validate the format of an e-mail address and also a captcha check.

Code: Select all

if ($username != "" || $fname != "" || $lname != "" || $email != "" || $password != "" || $vpassword != "" || $legaleagree != "") {
        //captcha procedure
        include "./captcha/audit.php";
        //e-mail validation procedure
        include "validate.php";

        $failed = "no";
        //e-mail check
        if ($email != "") {
                if (validate_email($email)) {
                } else  {
                        echo "<center><font color=red><b>Please type in a valid e-mail address</b></font></center>";
                        $failed = "yes";
                }
        }
        //captcha check
        if (audit() && $failed != "yes") {
        } else {
                echo "<center><font color=red><b>Please type in the correct text from the picture into the box below</b></font></cent$
                $failed = "yes";
        }
For some reason, with the e-mail format check left in the code, the captcha always returns false.

If I comment out the e-mail check, the captcha portion works properly.

I can post the modules if the info is needed.
i think it might have to do with the </cent$ at the end? tags incorrect i think.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

It is a little hard to tell with your inverse logic.

Code: Select all

if ($email != "") {
                if (! validate_email($email)) {
                        echo "<center><font color=red><b>Please type in a valid e-mail address</b></font></center>";
                        $failed = "yes";
                }
        }
        //captcha check
        if (! audit() || ($failed == "yes")) {
                echo "<center><font color=red><b>Please type in the correct text from the picture into the box below</b></font></cent$
                $failed = "yes";
        }
but I suspect the culprit is validate_email($email). Check it's return value.
(#10850)
Bigun
Forum Contributor
Posts: 237
Joined: Tue Jun 13, 2006 10:50 am

Post by Bigun »

Sorry, the <cent$ was due to nano's way of cutting off text that was too long.

I managed to but cram the audit.php function into the code without loading a module, it now looks like this:

Code: Select all

<?php

if ($username != "" || $fname != "" || $lname != "" || $email != "" || $password != "" || $vpassword != "" || $legalagree != "") {

        $failed = "no";

        //Captcha Check
        include "./captcha/audit.php";

        if (audit()) {
        } else {
              echo "<center><font color=red><b>Please type in the correct text from the picture into the box below</b></font></center>";
              $failed = "yes";
        }

        //init values for other stuff down the code
        $subject="CyberGrunge Account Validation";
        $from_header="From: DoNotReply@cybergrunge.com";
        $databaseusername="**********";
        $databasepassword="*********";
        $database="**********";

        //e-mail validation 
        if ($email != "") {

                // Create the syntactical validation regular expression
                $regexp = "^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$";

                // Validate the syntax
                if (eregi($regexp, $email)) {
                        list($username,$domaintld) = split("@",$email);
                        // Validate the domain
                        if (getmxrr($domaintld,$mxrecords)) {
                                //passed
                        } else {
                        $failed = "yes";
                        }
                }
        }
Post Reply