PHP: test session

Why is the structure fragile? I tried " !empty ( get_original_passhash() )

" as a condition, but it threw an error where you cannot use the return value.

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

      

+2


source to share


2 answers


I would be inclined to assign the variable before testing it, and maybe clean up the formatting a bit too:

$original_hash = get_original_passhash();

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

      

You also need to make sure you get_original_passhash()

return the correct type of the 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 should this code do? It connects to the database and then checks for a variable that just appears out of nowhere? Your code doesn't work because from the example you provided us, nothing gets installed. Is this the complete source code for this feature?

+2


source


You can split the logic:

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


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

+1


source







All Articles