Page 1 of 1

Code suggestions

Posted: Fri Aug 16, 2019 7:53 am
by iplayfast
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.

Re: Code suggestions

Posted: Fri Aug 16, 2019 8:22 am
by iplayfast
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());
}

Re: Code suggestions

Posted: Sat Aug 24, 2019 11:24 am
by kev1n
Thank you