kelleydl Posted September 16, 2009 Report Share Posted September 16, 2009 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 More sharing options...
Synook Posted September 16, 2009 Report Share Posted September 16, 2009 Well, if the username is in a session then you can retrieve the username from said session variable. Link to comment Share on other sites More sharing options...
kelleydl Posted September 16, 2009 Author Report Share Posted September 16, 2009 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 More sharing options...
justsomeguy Posted September 16, 2009 Report Share Posted September 16, 2009 You shouldn't use session_register, that's the really old way to use the session. Just use the $_SESSION array instead, you write and read to the $_SESSION array like any other array. You can use isset to check if a variable has been set in the session. Link to comment Share on other sites More sharing options...
chibineku Posted September 16, 2009 Report Share Posted September 16, 2009 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now