Jump to content

Sessions And Username


kelleydl
 Share

Recommended Posts

A user can log in and when they click submit takes them to a signin.php which just checks to make sure the user info is correct, and if so registers the username into a session. Then sends it back to the main page which checks to see if the user is registered in a session. I understand storing variable information, but how do I store the username which is registered into a variable? The w3schools tutorial shows how to increment page views into a variable but that doesn't help me understand how to retrieve the current username.

Link to comment
Share on other sites

let me try to rephrase this.. when the signin.php checks if its correct and it is, i do this.. //username comes from $_POST[username]session_register(username);header("Location:http://www. ");then in my index.php i have...<?php session_start(); if(!session_is_registered(username)){ header("Location:http://www. "); } $_SESSION['user'] = username;?><html>i don't get how to use the username that was registered in the prior page to store in a variable on the session_start() for use in any of my pages.

Link to comment
Share on other sites

The way I do it is just assign the session variable like this://check $_POST["username"] is not empty, sanitize it, check it exists, perhaps update a table with when the user last signed in$_SESSION["username"] = $_POST["username"];session_write_close();then to checkif($_SESSION["username"]) {//whatever you want to do with it} else {//deal with it not being set}I've not had any problems with that whatsoever, and that's all there is to it.

Link to comment
Share on other sites

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
 Share

×
×
  • Create New...