I'm making a web app in Haxe and compiling it to PHP. I test the PHP code on my local server (php -S
).
Here's the code:
//...
switch(page) {
//...
case "user":
//if logged in, display profile; if not, redirect to login
var loggedIn = false;
//check if user is logged in
if (Session.exists("username") && Session.exists("password")) {
var username:String = Session.get("username");
var password:String = Session.get("password");
//check the password
var conn = Mysql.connect({user: "..." pass: "...", host: "127.0.0.1", database: "..."});
var dbpass = conn.request("SELECT password FROM users WHERE username = \'" + username + "\';").results().first().password;
if (password == dbpass)
loggedIn = true;
}
if (!loggedIn) {
returnPage += File.getContent("../html/login.html");
} else {
//TODO add profile page
}
}
The server gives this error (no error when compiling):
uncaught exception: Unable to call <exists>
in file: /.../lib/haxe/ds/StringMap.class.php line 31
#0 /.../lib/Open.class.php(9): haxe_ds_StringMap->__call('exists', Array)
#1 /.../open/index.php(11): Open::main()
#2 {main}
And this is where the really weird part begins: When I change something in the code (it doesn't have to affect the app, even a comment would do), don't build it and reload the page, it suddenly works. But when i build the code, it gives the error again.
Is it some bug in the server or do I make a mistake somewhere?
I moved the testing server to Apache and the problem still persists.
I found out that the exists
function from the StringMap
class didn't get compiled to PHP for some reason, so i edited the code to be like this:
//...
if (Session.get("username") != null && Session.get("password") != null) {
and it works now. Don't know why the output changed when I didn't compile the file, but that doesn't matter.