Jump to content
Sign in to follow this  
flix_is_here22

retrieve the cookie?

Recommended Posts

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

Share this post


Link to post
Share on other sites

Look in the $_COOKIE array to see what was set:

print_r($_COOKIE);

  • Like 1

Share this post


Link to post
Share on other sites
Guest LH91325

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 by LH91325

Share this post


Link to post
Share on other sites

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

Edited by flix_is_here22

Share this post


Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
Sign in to follow this  

×
×
  • Create New...