Hi! I'm new. First question: about PHP login

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
Pri-K
Forum Newbie
Posts: 3
Joined: Tue Jan 06, 2009 11:54 pm

Hi! I'm new. First question: about PHP login

Post by Pri-K »

Hello everyone!
I'm new to the website, I hope can learn lots and lots in here.

I am actually a 2D animator, an artist and not a programmer. I am very interested in the subject though because I own a website (http://www.creu.com.br). With the help of my ex-boyfriend, I struggled to learn some PHP and MySQL basics to implement in the website, such as virtual cards and simple contact forms. I also know a bit of Actionscript , enough to keep the website's basics.

However, now that the website is growing, I have a lot more projects in mind, people want to see more things, interaction, games... all the stuff which I know will require a lot of programming. But I am committed to learn as much as I can.

One of the first things I'd like to know is how does a login system work. And by that, I also mean, how does the user create its own preferences, access privileged pages, store information, read exclusive news? How does that happen??
For example, let's say only registered users can play games. How does PHP store their high scores? How does it send the scores to MySQL so other users can see other user's high scores? Are they kept in the MYSQL forever?

Thank you very much.
I'm not looking for any scripts, just understanding the concept so I see what I can do first.
Pri-K
Forum Newbie
Posts: 3
Joined: Tue Jan 06, 2009 11:54 pm

Re: Hi! I'm new. First question: about PHP login

Post by Pri-K »

By the way, about the email forms.. I've been told that I can have many problems by creating PHP forms in SWFs, and sending information to MySQL via Flash instead of HTML.

Any comments on this??
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: Hi! I'm new. First question: about PHP login

Post by omniuni »

Well, almost all of this behavior is up to you.

MySQL is just a database, it stores what you tell it to, it removes it when you tell it to remove it.

PHP is just a programming language. You can have PHP store your high scores in a text file if you really wanted to, although it would probably be better off in a database.

The same goes for user logins. Usually, you have a register form, and the user fills it out, and upon successful completion, they are added to a database so they can log in. In general, you should avoid using Flash as much as possible. Keep your forms in HTML/CSS, and use PHP to process them. Just insert the Flash animations where you want them.

Does that help a bit?
Sephern
Forum Commoner
Posts: 73
Joined: Sun Jan 04, 2009 4:44 pm

Re: Hi! I'm new. First question: about PHP login

Post by Sephern »

A login system can be applied in 2 ways.

The first is to integrate it directly into the PHP code. Basically, you'll have a script which dictates all the users, and and how they login in the same document.
So they'll be a list of users, and in the same script, the code will basically check to see if the username exists, and if it does if the password matches. If they do the user will be able to access the content.

The second is more appropriate to your usage. You use a MySql database. In MySql, you can have a series of tables, each with different values. In the example of the games high scores, you could have-
A username field, which would show who the score belongs to, and carry out the other usual features of a username.
A password, to allow the user to login, and determine it is actually them.
A highscore field, which will contain the users highest game score.

You could then use PHP to find the username, and from there, get the high score and show it.

You can use MySql commands through PHP, to create, edit, delete, and query the data that is in the database. These simple four operations allow you to carry out a wide range of functions, and that is how a system similar to the one you are talking about would be created.
Pri-K
Forum Newbie
Posts: 3
Joined: Tue Jan 06, 2009 11:54 pm

Re: Hi! I'm new. First question: about PHP login

Post by Pri-K »

Wow, thank you so much, guys! All this info refreshed my mind very much, it's just what I needed.

Let's see if I understand, so basically, in the database, there's a variable that stores the high scores, and then the PHP gets this variable from the database to show to the users in a HTML code, and only the ones that are logged in. Correct?

But how far does this go, I mean, let's say I have 100 users playing the game, 'trying to modify' the variable of high scores? How does that work, how does it update?
And how does MySQL know the game that's being played (of course I would just want one high score variable per game). I can't set a 'variable' for a Flash game, can I?

There are some things, however, I still don't undertand. For instance, as this website also has, a 'user control panel'...
>> So let's use for example the avatar images.. well, everytime I want the specific image to appear, I just write down a variable in the HTML code that PHP will retrieve from MySQL, right? But there are hundreds of users! Is there a variable for each image, for each user..?? :?:
>> And let's say I have the option to change the colors of my panel, meaning that would require the HTML to call a different CSS file (right?). How does MySQL 'save' this information? I mean, how does it 'remember'?? Is that set up like variables?

Thank you sooo much!!
Sephern
Forum Commoner
Posts: 73
Joined: Sun Jan 04, 2009 4:44 pm

Re: Hi! I'm new. First question: about PHP login

Post by Sephern »

Pri-K wrote:Wow, thank you so much, guys! All this info refreshed my mind very much, it's just what I needed.

Let's see if I understand, so basically, in the database, there's a variable that stores the high scores, and then the PHP gets this variable from the database to show to the users in a HTML code, and only the ones that are logged in. Correct?
No. There is a field in the database storing the high score. Like a column. The Variable is set in the PHP. You set the variable to whatever is in this field, corresponding to the username. For example, if you want the high score of 'user1', you'll find the 'user1' username and their high score in the database, and set that field as the variable. You can then use this to show the variable, and it will update itself, rather than being hardcoded, where you have to update manually.
Pri-K wrote:But how far does this go, I mean, let's say I have 100 users playing the game, 'trying to modify' the variable of high scores? How does that work, how does it update?
you can use PHP to update fields in a database. As the users all have different usernames, it will be updating 100 different fields.
Pri-K wrote:And how does MySQL know the game that's being played (of course I would just want one high score variable per game). I can't set a 'variable' for a Flash game, can I?
I don't know, since I don't have any flash experience. If you can, I imagine it would be a function in Actionscript, but I really don't know. Sorry.
Pri-K wrote:There are some things, however, I still don't undertand. For instance, as this website also has, a 'user control panel'...
>> So let's use for example the avatar images.. well, everytime I want the specific image to appear, I just write down a variable in the HTML code that PHP will retrieve from MySQL, right? But there are hundreds of users! Is there a variable for each image, for each user..?? :?:
Again, each field is different. You will write the script so that the username that the user logs in with is a variable. You then use that variable to find the users information in the database. What I would do is get the PHP to save the avatar as html. Then echo it in the appropriate place. For example-

Code: Select all

$username = $_POST ['username'];
$avatarquery = mysql_query("Select Avatar from Accounts Where username='$username'");
$avatar = mysql_result ($avatarquery, 0, "Avatar");
echo $avatar;
Naturally, this is just a very basic example and would have to be customized to what you want it to do, and your table.
Pri-K wrote:>> And let's say I have the option to change the colors of my panel, meaning that would require the HTML to call a different CSS file (right?). How does MySQL 'save' this information? I mean, how does it 'remember'?? Is that set up like variables?
Similarly, this would be set up in a database field. This would probably call a CSS, and you would do it similarly to the avatar.
Pri-K wrote:Thank you sooo much!!
Np ^^ happy to help. Hope this makes your understanding clearer.
Post Reply