I've been working on a game using the Facebook Platform and have much work completed in the past week. Now I've got several parts of this game completed that I've been working on and learned a great deal about PHP and MySQL working together. I've got a game that uses PHP to modify an SQL database extensively but I have one feature that is key to the success of the game that I am stumped on. To be honest I'm not even sure where to begin but I have some general ideas.
I basically want to set a session I believe when a person first visits the game for the day. Facebook passes along the user information each time we have a hit on the page. I want to take that information (which is stored in a database using the following code)
$con = mysql_connect("$db_ip","$db_user","$db_pass");
if (!$con)
{
die('Error Adding UserID: ' . mysql_error());
}
mysql_select_db("$db_name", $con);
mysql_query("INSERT INTO Users (UserID)
VALUES ('$user')");
// Create Record From User ID Number
and throw in a logged in time to the database such as (start_time) and then start a countdown from four hours. Basically each user gets a token bonus every four hours that they login to spend inside the game. So basically if they come back to the application within four hours they won't get the bonus but after the fourth hour from the previous login they will. I already have created the code that awards the bonus and it is here:
mysql_query("UPDATE Users SET Units = '$new_currency' WHERE UserID='$fetch_id'");
The $new_currency function is elsewhere in the code and performs the fetch of the original currency plus the new currency before updating the SQL query.
I'm thinking the best way to do this is a PHP session but honestly I have no idea. My original thought was that I need to store in the database the login time and then use some form of PHP to countdown those four hours before executing the "bonus" section of the code.
Any thoughts? What would be the best way to go about this? I'm new to this so if you need more information or I need to do a better job explaining what I need please let me know.

New Topic/Question
Reply




MultiQuote





|