I don't think this would be hard for a clever lad, you're just looking at the wrong end of the code. Mysql has both "if" and "time" functions. Have
PHP send the query and do the coding on the mysql end. You might even think about having the "sorry, try again tomorrow" code in the database!
Otherwise, you're looking at multiple queries and a convoluted mess of
php. I think doing the "if" code in mysql is going to be a lot cleaner, after all is said and done. Once you get the complex query working, you'll have one (longish) line of code that will do the whole thing.
Another thought is that you might do an initial query to check the time-counter, and just lock the person's access.
I'd almost do this for you just for fun/learning -- my mysql could really use some study time -- except I suspect you'll enjoy doing it yourself.
As a personal preference, I would not use any global variables except $_POST for this (or any page where user input can result in a change to the db).