Jump to content

Recommended Posts

Posted

I want to control the user name which is loggin into the application. Once the user is logged in, the username should be saved through out the system until the user logged out. For that matter, how can i keep the user name? Should i use cookie or session? How is the difference and which is better?

Is anything sample to use these, please let me see.

Thanks.


Posted (edited)

A session will not store the username, session is just unique id you can assign on login or initial page load, and check on subsequent requests to make sure it is actually logged in user.

To have the user name available you can either use cookies, or if you want to support browsers with cookies disabled you can pass the name from request to request in a hidden input form field.

Edited by dman
Posted

You CAN store values (variables) in both sessions and cookies (though many session-engines uses cookies for it).

But the way you do it, depends alot on what language you're using.

Posted
You CAN store values (variables) in both sessions and cookies (though many session-engines uses cookies for it).

But the way you do it, depends alot on what language you're using.

You are right of course stalkie.

// Get the user's input from the form
  $name = $_POST['name'];

// Register session key with the value
  $_SESSION['name'] = $name;

I was thinking of the built-in session variables, but you are correct, you can register your own in the session.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...