Jump to content

User Id's and creating accounts.


Dark57

Recommended Posts

So I just got finished with writing my login/register script so that people can now log into the website.  Now I want them to have there own account, similar to this website in a sense.  When people register an account they must provide an ID, Username, Password, and Email.  I want to know what is the best, most efficient way to figure out what their user ID is so that I can start recalling information from tables inside the database.  This is a basic game text based game I am trying to develop if that helps you understand what I'm trying to accomplish.

Link to comment
https://forums.phpfreaks.com/topic/197921-user-ids-and-creating-accounts/
Share on other sites

You don't want them setting their own ID, you want that to be done automatically via autoincrement in the MySQL table where you're storing their info.

 

For example:

 

table - users

ID (int, 10, auto-increment, KEY) | username (varchar, 255, unique) | email (varchar, 255) | password (varchar, 255)

 

And then when they sign in, it will set their USER ID (ID) to the next available number and that will always be their ID.

 

Also, in your login script, when they log in, you can simply set their information into global session variables, such as:

 

$_SESSION['userID']==$ID; (which you've gotten from a simple sql query looking up their username)

$_SESSION['username']==$username;

 

and then anywhere in your script, you can simply call them back like:

 

echo "Hi ".$_SESSION['username'].", it's nice to see you again!";

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.