use this function if session function return true it gets the user data and use it to connect to database
use this function if session return false. you should feed this function with username and password because it uses them to connect to database. it alse write this data to a cookie file for farther use.