How can you have only one declaration of the database connection variable, $dbconn
?
My login script is based on the following procedure
- If the user is not authenticated, he is thrown back to the login page
- If the user is authenticated, he gets an
$_SESSION["logged_in"] = true;
- Then when the user is browsing the main page or other pages that need auth, they just check if the $_SESSION["auth"] is set.
I have the database variable only at the beginning of my index.php:
$dbconn = pg_connect("host=localhost port=5432 dbname=masi user=masi password=123");
I do not the connection by db_close()
anywhere in my codes.
I source my login script to index.php which uses my database.
However, I get the standard warnings of not getting access to db when I do not have the variable declaration also in my scripts. If I add the declaration to each of my scripts, I get an access to db.