SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict thoresson's Avatar
    Join Date
    Dec 2002
    Location
    Gothenburg, Sweden
    Posts
    255
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    function doens't return

    Hi,

    After a new user has filled in a form to register for my site, I check that she has entered the same password
    twice by calling a homemade function. Like this:
    PHP Code:
     $u_pwd validate_password($_POST['u_pwd'],$_POST['u_pwd1']); 
    And the function looks like this:

    PHP Code:
    function validate_password($unchecked_password1$unchecked_password2$errortype 1$errormessage "Password 
    must contain just letters and figures."
    ) {

    if(!(
    $unchecked_password1 == $unchecked_password2)) {
    error("Passwords entered doesn't match!");
    }
     
    if(!
    ereg("(^[a-zA-Z0-9]{6,15}$)"$unchecked_password2)) {
    if(
    $errortype == 1) {
    error($errormessage);
    }
    Return 
    1;
    }


    I have verified that $_POST['u_pwd'] and $_POST['u_pwd1'] as well as $unchecked_password1 and
    $unchecked_password2 contains the entered values, but $u_pwd is empty.

    Why?

    As with my previous problems this evening, it works on my local server, but not on my ISP's. At home I'm running
    Windows 2000 and PHP 4.3.1, while my ISP is on SunOS 5.7 with PHP 4.1.1.

  2. #2
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you saying that your function returns, without generating error()s, and still $u_pwd is empty?

    Or does it always generate the error()s, regardless of the values entered?
    My name is Steve, and I'm a super-villian.

  3. #3
    SitePoint Addict thoresson's Avatar
    Join Date
    Dec 2002
    Location
    Gothenburg, Sweden
    Posts
    255
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lieut_data
    Are you saying that your function returns, without generating error()s, and still $u_pwd is empty?
    Yes. If two different passwords are entered, I get an error, but when the same are entered, the function returns nothing.

    //Anders

  4. #4
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't know why it works on your computer, but as you can see below, the old return statement only executed if the passwords have invalid characters. I have added a second return statement which executes it they do not.

    PHP Code:
    function validate_password($unchecked_password1$unchecked_password2$errortype 1$errormessage "Password 
    must contain just letters and figures."


    {

    if(!(
    $unchecked_password1 == $unchecked_password2)) 
    {
       
    error("Passwords entered doesn't match!");
    }
     
    if(!
    ereg("(^[a-zA-Z0-9]{6,15}$)"$unchecked_password2)) 
    {
       if(
    $errortype == 1
       {
          
    error($errormessage);
       }
       
    //This one only executes if password contains invalid chars, don't  
       //need it since error() handles that for us
       //Return 1;
    }

    //Missing return statement here
    Return 1;


    My name is Steve, and I'm a super-villian.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •