Reply
4 Questions [User System; temporary data; timed scripts; (off-topic)]
Old 03-05-2007, 04:44 PM 4 Questions [User System; temporary data; timed scripts; (off-topic)]
InfinitySchima's Avatar
Skilled Talker

Posts: 69
Name: Rafael Schimassek
Hello to all,
I'm currently starting off with PHP and MySQL (learning it for ~2 weeks now) and came up with a couple of question which I would be very grateful to get some help in them.
I'm going to make all of this a bit more appealing for better understanding. And there are some off-topic ones but I thought I would better put everything in one post other than creating now about 3 other topics.

Question 1:
Concerning: HTML, PHP, MySQL
Info: I need this info for a User Database of a game I am creating. It's a simple database with [ID, Username, Password, E-Mail], which is then going to be used for the user being able to login into the game. I already managed to create a simple user database where you could register yourself (still haven't made anything with password hashing or so, I'll look to that later.) and a script which showed all the Users already registered (have also some basic knownledge in MySQL).
Question: What I needed was some help in how to make it that you login into the server and have access in some pages which you wouldn't have access to if you wouldn't be logged in. Also on the game certain pages should only show the user's personal info and not from the other ones (but that I might be able to figure out by myself).
Post Question: And I might need to have some code to Logout the user so that he cannot access certain pages anymore from that computer without signing in again? And how to do it, if the user doesn't clicks on the Logout button and instead closes the window.

Question 2:
Concerning: PHP, MySQL
Info: First of all, the test version was supposed to have a 5x5 panel map where you could walk around (an example of this would be Urbandead or PokemonCrater), I've thought of integrating a message system, where you could leave a/or more message(s) on the panel for other users being able to see them, but to avoid a huge mass of data I needed something that would delete those message from time to time, or, even better, but maybe more difficult, a system on which each user would only see the new messages from his last login (although there still would be a message delete from time to time).
Question: Could anyone give me some info on how to create a script which would (in this case) delete some data from time to time, and first evaluate on what time the message was written to decide whether it should delete the message or not.
Side Question: And how do I actually add time on a message.

Question 3:
Concerning: Apache, MySQL, PHP?
Info: For example, on some games you have an energy bar which is used if you perform an action; and which recovers over time while you are logged out. I wondered about the "Energy Recovery" part.
Question: How can I perform this operation of adding a certain amount to a variable from time to time (good would be already from hours to hours, even better would be from instant to instant)?
Post Script: At the moment I am running an localhost server with Apache on my own computer (and obviously I shutdown and restart the server many times), do this interferes with the operation above?

Question 4:
Concerning: MySQL (Off-Topic)
Info: The game is going to have a big database where are stored all the user's skills, items, locations, etc. And I had "little" doubts about how I should add all the users information into the database. I thought of 2 methods, the first one (which for me is the worst one) is: I create a Table for each user (name being the username) where the fields would be every skill, every item, etc (in example: Skill1 , Skill2 , Skill3 , Item1 , Item2 , Item3 , ...), and it would have 1 row, displaying his skill level / number of the item held. The second method (which I think is the best) is to create a huge Table where the fields would be username, every skill, every item, etc.; It would have more rows according to the number of users.
Question: Which method is the best: "Method 1 with a Table for each Username" or "Method 2 with a huge Table for all users"?

Question 5:
Concerning: PHP
Info: In the game, of course, I need to add a luck factor somewhere, and for this I needed to know how to generate random numbers, let's say from 0 to 100. I've searched a lot in the net already but haven't found anything useful yet.
Question: How do I create random numbers in PHP?


Additional Info:System: Windows XP (Professional)
PHP: Version 5.2.1
MySQL: Version 5.0.33
Apache: Version 2.2.4

I hope not to ask too much (or maybe I am already ). Any help on any question would help me a lot. And if you need any more info let me know.

Thanks in advance.

Last edited by InfinitySchima : 03-06-2007 at 05:15 PM. Reason: Added a question (5) and some info
InfinitySchima is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 03-05-2007, 05:20 PM Re: 4 Questions [User System; temporary data; timed scripts; (off-topic)]
Republikin's Avatar
Super Moderator

Posts: 3,191
Question 1: PHP has very limited post-processing features however, if your using sessions to store user login info then I would not worry about them logging out. If they close their browser, their session is automatically destroyed.

Question 2: Actually deleting the message is a simple as running a SQL query to delete a record. Also, look into time stamps in SQL, you can add them to every row automatically. As well, look into CRON as this is an excellent way to run a script at set intervals and most every *nix based host has it.

Question 3: The trick is not to store it in a variable for long periods of time, instead throw this info into the database and just retrieve it when neccesary.

Question 4: Method 2 is the most sane and is the way everyone does it. Creating a table for each member would be an insane waste of resources.
Republikin is offline
Reply With Quote
View Public Profile
 
Old 03-06-2007, 05:04 PM Re: 4 Questions [User System; temporary data; timed scripts; (off-topic)]
InfinitySchima's Avatar
Skilled Talker

Posts: 69
Name: Rafael Schimassek
Re: to Republikin

1. I see, so, do I create Sessions with PHP only then? Is there a good site with things like this, it's quite a pain to search for the keywords "login" and "session" in Google or any other.

2. I will search for this CRON then.

3. Hmm, what you wrote was about the Post Script, am I right? About the add of variable from time to time, I think I may be able to use it with that CRON thing (PS: Do I have to install a programme for it, or does it already comes integrated in PHP5?)

4. Thanks


Edit: It seems to me that CRON is used by Linux Users, what can I do about it as a Windows user?

Last edited by InfinitySchima : 03-06-2007 at 05:41 PM. Reason: Linux?
InfinitySchima is offline
Reply With Quote
View Public Profile
 
Old 03-06-2007, 06:13 PM Re: 4 Questions [User System; temporary data; timed scripts; (off-topic)]
Republikin's Avatar
Super Moderator

Posts: 3,191
Session variables are native to PHP and you will actually get quite a bit of good links by typing "php sessions" into Google.

Post Script is something completely different than what I'm talking about. Basically, you want your users data to save state; what this means is you don't want it to go away when they close the browser or refresh the page, so on each page refresh or page change you put their accumulated rank in the database so that it is then available to every page at any time.

As far as Cron for windows goes, I'm not that sure there is a native solution and if there was it would surely cost your host something. The next best solution (although really not ideal) is to create a php script that will be run on every page view (or every other, etc until you strike a good balance) that will update the info you want updated.
Republikin is offline
Reply With Quote
View Public Profile
 
Old 03-06-2007, 06:24 PM Re: 4 Questions [User System; temporary data; timed scripts; (off-topic)]
InfinitySchima's Avatar
Skilled Talker

Posts: 69
Name: Rafael Schimassek
Quote:
Originally Posted by Republikin View Post
Post Script is something completely different than what I'm talking about. Basically, you want your users data to save state; what this means is you don't want it to go away when they close the browser or refresh the page, so on each page refresh or page change you put their accumulated rank in the database so that it is then available to every page at any time.
The part of storing the value in the database I already know, what I was asking is how add an amount to that variable from time to time.

Quote:
Originally Posted by Republikin View Post
As far as Cron for windows goes, I'm not that sure there is a native solution and if there was it would surely cost your host something. The next best solution (although really not ideal) is to create a php script that will be run on every page view (or every other, etc until you strike a good balance) that will update the info you want updated.
Does PHP or MySQL have some sort of add a time and date. So I could create a script which would first check how old the message was, and if it were older than a certain amount the message would be deleted.

Thanks again for your help.
InfinitySchima is offline
Reply With Quote
View Public Profile
 
Old 03-06-2007, 06:51 PM Re: 4 Questions [User System; temporary data; timed scripts; (off-topic)]
Republikin's Avatar
Super Moderator

Posts: 3,191
Use the SQL UPDATE query, you can google this to get some great examples of how it's used.

You can use both PHP and MySQL to do a timestamp. The prefered method would be to use MySQL to set and update the timestamp as this is a data type in MySQL just like INT or TEXT and then use PHP to check how much time has passed, etc. in order to perform operations based upon time.
Republikin is offline
Reply With Quote
View Public Profile
 
Old 03-07-2007, 02:07 PM Re: 4 Questions [User System; temporary data; timed scripts; (off-topic)]
InfinitySchima's Avatar
Skilled Talker

Posts: 69
Name: Rafael Schimassek
I understand, thanks again for all your help. I will look now into the diferent sections which were talked in here.
Although even more info in here would help me even more .
InfinitySchima is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to 4 Questions [User System; temporary data; timed scripts; (off-topic)]
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.21361 seconds with 13 queries