Re: Sometimes I wonder why I even started programming...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 27 Feb 2008, at 22:16, Jason Pruim wrote:
On Feb 27, 2008, at 5:12 PM, Daniel Brown wrote:
On Wed, Feb 27, 2008 at 4:55 PM, Jason Pruim <japruim@xxxxxxxxxx> wrote:
      function authentication($user, $pass, $authenticated, $table){

                      // Keep in mind, PASSWORD has meaning in MySQL
                      // Do your string sanitizing here
// (e.g. - $user = mysql_real_escape_string($_POST['user']);)
                      $salt = "salt";
                      $salt1 = $salt;
                      $salt1 .= $pass;

                      $password = md5("$salt1");
$loginQuery = "SELECT * FROM current WHERE loginName='".$user."'
AND loginPassword='".$password."' LIMIT 0,1;";
$loginResult = mysql_query($loginQuery) or die("Wrong data supplied
or database error"  .mysql_error());
while($row1 = mysql_fetch_array($loginResult)) { $_SESSION['user'] = $row1['loginName'];
                              $_SESSION['loggedin'] = "YES";
                              $authenticated = "true";
                              $table = $row1['tableName'];

                      }
              return $table;
              return $authenticated;
      }       \
  As soon as a function reaches a `return` statement, it returns
that data and exits, so the second `return` is never processed.

so the "return $table;" line doesn't ever get processed?

Nope, only return $table will get processed since that ends execution of the function.

Is there anyway to make it get processed? :) I'm attempting to rewrite code so I don't HAVE to use session variables... Hoping I can make it work :)

To return multiple values from a function it's usually best to return an array. There are other ways to do it such as out parameters but returning an array should be sufficient in this case.

Replace your two return statements with the following...

return array($table, $authenticated);

Then call the function like this...

list($table, $authenticated) = authentication(blah, blah, blah);

-Stut

--
http://stut.net/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux