flix_is_here22 Posted May 15, 2012 Share Posted May 15, 2012 hi, i so confused with retrieve the cookie when retrieve the cookie in the other file....i have some file....1. login.php -----> this file have a action form to checklogin.php2. checklogin.php -->cookie usrname to be set and the end of code i put header("location: home.php")3. home.php ---> menu of my website after user login. so i really confused when i retrieve the cookie usrname in the file home.php.....how to retrieve the cookie of usrname into home.php....??i has been try this code :echo $_POST["usrname"]; orecho $_COOKIE["usrname"];but both of this code isn't work..... :fool:any sugesstion?? Link to comment Share on other sites More sharing options...
Ingolme Posted May 15, 2012 Share Posted May 15, 2012 Look in the $_COOKIE array to see what was set: print_r($_COOKIE); 1 Link to comment Share on other sites More sharing options...
Guest LH91325 Posted May 15, 2012 Share Posted May 15, 2012 (edited) It is $_COOKIE["usrname"] where "usrname" is the name of your cookie. It needs single or double quotes around the name because that is the array index. Use your browser to verify that your set cookie code actually worked. Like Firefox -> Tools -> Options -> Privacy -> Show Cookies. If it is not there then look at your set cookie code. If it is there and the name is correct then look at your check cookie code. When you get that working it's more sophisticated to have your login.php action back to itself. Then it can verify correct cookie and die(header('Location: /home.php')); Or if there's an error (wrong password) it can repeat the login form and fill the username field to make it easier to try again. Edited May 15, 2012 by LH91325 Link to comment Share on other sites More sharing options...
flix_is_here22 Posted May 16, 2012 Author Share Posted May 16, 2012 (edited) hahaha... :rofl:thx both of you for reply.... i really hopeless yesterday so i get some idea. i change process to get cookie using creating file and put the cookie in the their file.....so i can show the cookie everytime i want..... :rofl:honestly i bit cheating about retrive the cookie.... Edited May 16, 2012 by flix_is_here22 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