phpSensei Posted July 13, 2007 Share Posted July 13, 2007 I have a few questions regarding user loggin in. First I am going to skip the part where we see if the post is set, or if the user matches the same one in the database. Lets say everything is okay, and when success the user session is registered. Now here is my question; "WHAT needs to be Registered?". <?php session_register['username']; session_register['password']; ?> Or do I need to register a user id.... Totally confused here, help me out. Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 13, 2007 Share Posted July 13, 2007 its upt to you you put what you will need like if you wan to display the name of user ind every page then use name and if you only need to do the authentication use id any way you can use both but its a good thing to minimize using session Quote Link to comment Share on other sites More sharing options...
MadTechie Posted July 13, 2007 Share Posted July 13, 2007 Personally i use $_SESSION as its is preferred, as of PHP 4.1.0 start_session(); $_SESSION['username'] = "MadTechie"; $_SESSION['password'] = "notsaying"; echo "Hello ".$_SESSION['username']; instead of storing the username store the UserID, and a hashkey instead of password.. link the hashkey to another table that is created on login, this is a long topic! Quote Link to comment Share on other sites More sharing options...
phpSensei Posted July 13, 2007 Author Share Posted July 13, 2007 Personally i use $_SESSION as its is preferred, as of PHP 4.1.0 start_session(); $_SESSION['username'] = "MadTechie"; $_SESSION['password'] = "notsaying"; echo "Hello ".$_SESSION['username']; instead of storing the username store the UserID, and a hashkey instead of password.. link the hashkey to another table that is created on login, this is a long topic! I still do not understand what hash key is, I know how to use it but whats it good for? md5 right? How do you insert the userID with sessions? Quote Link to comment Share on other sites More sharing options...
d22552000 Posted July 14, 2007 Share Posted July 14, 2007 $hash = md5($VARIABLE); Quote Link to comment Share on other sites More sharing options...
phpSensei Posted July 14, 2007 Author Share Posted July 14, 2007 What does the HASH do? How do you insert sessions into a Database? Quote Link to comment Share on other sites More sharing options...
MadTechie Posted July 14, 2007 Share Posted July 14, 2007 I still do not understand what hash key is, I know how to use it but whats it good for? md5 right? How do you insert the userID with sessions? Hash is used for secuirty.. and yes md5 is a one way encryption aka hash.. to use sessions see the examples.. ie.. $_SESSION['userid'] = $userid; i think to need to research some more and then plan the design as your not clear on a few keys elements. start small create a simple login script then add to it a little at a time. sessions will be used to keep the user logged in. when your finished you may wish to start again, as you would of learnt a few things please don't take any of that the wrong way.. Quote Link to comment Share on other sites More sharing options...
trq Posted July 14, 2007 Share Posted July 14, 2007 What does the HASH do? Hides (like encryption) data within a string. How do you insert sessions into a Database? Why would you want to? Also note... there is generally no reason to store a users password in a session. All you need store is enough infomation to recognise a particular user and sometimes an access level. Quote Link to comment Share on other sites More sharing options...
phpSensei Posted July 14, 2007 Author Share Posted July 14, 2007 Alright, I finished the script. I have registered a session just when the user logs in. Now once the session is registered, but how do you use this information? like this: $_SESSION['username']; ? Quote Link to comment Share on other sites More sharing options...
MadTechie Posted July 14, 2007 Share Posted July 14, 2007 WHAT!!! i have no idea.... depends what you want to use it for!! i'm going to bed.. night all! Quote Link to comment Share on other sites More sharing options...
phpSensei Posted July 14, 2007 Author Share Posted July 14, 2007 I want to show the users login information when he is on the index page. Quote Link to comment Share on other sites More sharing options...
trq Posted July 14, 2007 Share Posted July 14, 2007 A simple example. p1.php <form action='p2.php' method='post'> <input type='text' name='uname'> <input type='submit' name='submit'> </form> 2.php <?php if (isset($_POST['submit'])) { session_start(); $_SESSION['uname'] = $_POST['uname']; echo "<a href='p3.php'>link</a>"; } ?> p3.php <?php session_start(); echo $_SESSION['uname']; ?> Quote Link to comment Share on other sites More sharing options...
phpSensei Posted July 14, 2007 Author Share Posted July 14, 2007 A simple example. p1.php <form action='p2.php' method='post'> <input type='text' name='uname'> <input type='submit' name='submit'> </form> 2.php <?php if (isset($_POST['submit'])) { session_start(); $_SESSION['uname'] = $_POST['uname']; echo "<a href='p3.php'>link</a>"; } ?> p3.php <?php session_start(); echo $_SESSION['uname']; ?> I managed to loggin the user but! What if I wanted to show the users statistics, like number of post and date he joined my site... How would you use the SELECT statement for this? Quote Link to comment Share on other sites More sharing options...
trq Posted July 14, 2007 Share Posted July 14, 2007 How would you use the SELECT statement for this? If you want this data in a session var get it when you check the users credentials to log them in. Post your code if your stuck... otherwise use the examples that have already been posted. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.