tags:

views:

52

answers:

2

Why is the construction brittle? I tried "!empty ( get_original_passhash() )" as a condition, but it ignites the error that you cannot use the return value.

if (  get_original_passhash () != '' ) 
{
    set_login_session ( get_original_passhash() );
}else
    print("Please, log in.");
+2  A: 

I would be inclined to assign the variable before you test it, and probably also clean up your formatting a little too:

$original_hash = get_original_passhash();

if ($original_hash != ""){
    set_login_session(get_original_passhash());
} else {
    print("Please Log In");
}

You should also ensure that get_original_passhash() is returning the right type of variable - interger, string, boolean, etc.

Edit:

function get_original_passhash(){
    $dbconn = pg_connect("host=localhost port=5432 dbname=heoa user=heoa password=123");

    if(!empty($passhash_session)){
        return $passhash_session;
    } else {
        return $passhash_post;
    }
}

What is this code supposed to do? It connects to a database, and then tests a variable that just appears out of nowhere? Your code isn't working because, from the example's you've provided us, nothing is even being set. Is this the full source code for this function?

EvilChookie
+1 good point, the function get_original_passh was unnecessary.
HH
+1  A: 

You may want to split up your logic:

if (is_logged_in()) {
  set_login_session(get_original_passhash());
} else {
  print("Please Log In");
}

Since, in the conditional, you don't want the pass hash. You want to know if they're logged in or not.

Lucas Oman
+1 for targeting clarity
HH