Wednesday, November 5, 2008

PhotoShare Progress

Chugging along on the PhotoShare project. It is making me grateful for frameworks like Wordpress, Joomla, et al that have plug-and-play register/log-in/log-out code that can be implemented in seconds. Nonetheless, this has been helpful in learning how to manipulate those existing code samples.

I am almost done with the account creation and state management bit. I had some trouble on the log in functionality because I was trying to use If/Else to handle what happened when the log in credentials did or didn't match. I was experimenting different combos with exit and quit AFTER the while loop. The result was that I could either:

1. Log in successfully with any of the entries in the database, but the error message on failure printed many times (once for each line in the database) or
2. Get the error message to print exactly once on failure, but I could only successfully log in with the first line of the file. (in other words, it was just checking the first row then quitting.)

A quick peek at David's code showed an If statement with an exit inside the while loop to handle succesful log ins with failed log in being handled outside the loop. I implemented it that way and it worked beautifully. (Thanks Dave).

So, that and the cookies all work now. I am handling errors on the log in page for now until I can figure out how to redirect to the home page with a custom error message. My original plan was to have the failed log in place a cookie that could trigger an appropriate error message when it redirected to the log in page. Going back to delete that cookie might be complicated though. I would probably need to attach a cookie deleter to the log in submit button so that error message didn't keep showing, which doesn't seem very elegant. I could delete the cookie at the beginning of the processlogin.php file but if the user doesn't attempt log in again and goes to other areas of the site, then returns, the error message would still be there.

Hmmm.....Has anyone tried using cookies to handle this portion?

2 comments:

nycbone said...

About the errors: From the login, if it fails I just redirected back to the login page using the header function and at the end of the link placed a true variable that would trigger an error message on the login page.

header("Location: ../page_login.php?noLogInMatch=1");

I think that relates to your last question.
dave bone

Larry said...

Yep, that was the answer and was a much cleaner solution than the one I was going to use. Thanks!