Jump to content

[SOLVED] Using Sessions On login.


phpSensei

Recommended Posts

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. :P

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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..

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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'];

?>

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.