X-Git-Url: https://dev.renevier.net/gitweb.cgi?p=syp.git;a=blobdiff_plain;f=api.php;h=2dbfac4857a88e258513b114b3dcdb262ad770a3;hp=9b268dcaf31beb8ac4bbc0e4e7b577c9d44909fc;hb=81b566d916827fa6ee03b6fbf06c180ec249e7e7;hpb=1fa9f86af76141dee786b45083ebcdb72f49981a diff --git a/api.php b/api.php index 9b268dc..2dbfac4 100644 --- a/api.php +++ b/api.php @@ -3,7 +3,8 @@ license. */ function exit_document ($body) { - exit ("$body"); + $charset_meta = ''; + exit ("$charset_meta$body"); } function success ($reason) { @@ -192,8 +193,14 @@ function setcookies ($user, $pwd) { // cookie will be valid for 2 weeks. I've chosen that value // arbitrarily, and it may change in the future. $time = time () + 14 * 60 * 24 * 60; - setcookie (sprintf ("%sauth", DBPREFIX), md5 ($pwd), $time, "" , "", false, true); - setcookie (sprintf ("%suser", DBPREFIX), $user, $time, "" , "", false, true); + if (version_compare (PHP_VERSION, '5.2.0', '>=')) { + setcookie (sprintf ("%sauth", DBPREFIX), md5 ($pwd), $time, "" , "", false, true); + setcookie (sprintf ("%suser", DBPREFIX), $user, $time, "" , "", false, true); + } else { + setcookie (sprintf ("%sauth", DBPREFIX), md5 ($pwd), $time, "" , "", false); + setcookie (sprintf ("%suser", DBPREFIX), $user, $time, "" , "", false); + } + } function check_auth ($con, $user, $pwd, $auth_only) { @@ -337,6 +344,9 @@ function main ($con) { try { $con->setpwd ($user, $newpass); } catch (Exception $e) { + if ($e->getMessage () == anydbConnection::err_query) { + error_request (); + } error_server (); } setcookies ($user, $newpass); @@ -357,6 +367,9 @@ function main ($con) { try { $con->setpwd ($newuser_name, $newuser_password); } catch (Exception $e) { + if ($e->getMessage () == anydbConnection::err_query) { + error_request (); + } error_server (); } success_newuser ($newuser_name); @@ -372,7 +385,7 @@ function main ($con) { if (!@include_once ("./inc/settings.php")) { error_server (); } -require_once ("./inc/db/mysql.php"); +require_once ("./inc/db/" . (defined ("DBTYPE")? DBTYPE: "mysql") . ".php"); require_once ("./inc/utils.php"); try {