I've got a few ideas for your code, (little ones) but I don't see a github or some such link to offer them.
So here they are. nudatabase.php should fail gracefully if the user doesn't have a config set up correctly.
try {
$nuDB = new PDO("mysql:host=$DBHost;dbname=$DBName;charset=$DBCharset", $DBUser, $DBPassword, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES $DBCharset"));
}
catch ( PDOException $e) {
die($e->getMessage());
}
I'm not sure what's going on with your standalone session, you are checking to see if any var are set and if so, the user must be logged in? This system doesn't work if someone decided to edit the nuconfig.php after attempting to log in incorrectly. (my case). Stuck between active session but not logged in.
I'm not sure of the correct way to do this, but I'm sure this is wrong.
Welcome to the nuBuilder Forums!
Register and log in to access exclusive forums and content available only to registered users.
Register and log in to access exclusive forums and content available only to registered users.
Code suggestions
-
- Posts: 2
- Joined: Fri Aug 16, 2019 7:44 am
Re: Code suggestions
The following code removes the session if the database dies, allowing you to try again.
try {
$nuDB = new PDO("mysql:host=$DBHost;dbname=$DBName;charset=$DBCharset", $DBUser, $DBPassword, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES $DBCharset"));
}
catch ( PDOException $e) {
unset($_SESSION['nubuilder_session_data']);
die($e->getMessage());
}
try {
$nuDB = new PDO("mysql:host=$DBHost;dbname=$DBName;charset=$DBCharset", $DBUser, $DBPassword, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES $DBCharset"));
}
catch ( PDOException $e) {
unset($_SESSION['nubuilder_session_data']);
die($e->getMessage());
}