473,395 Members | 1,595 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

When I click on ‘remember me’ and after sign out, when I try again to login cookies a

I have a login form in which i have a username, password and a remember me radio button option. Now I want it so that when I've signed out from home page and I try again to login then without asking for a username and password I get logged in because I am going to store the username and password values into cookie.

I wrote code on password_match.php page(action page of login page)
Expand|Select|Wrap|Line Numbers
  1. $con=mysql_connect("localhost","root","");
  2. if(!$con)
  3. {
  4. die('Could Not Connect:'.mysql_error());
  6. mysql_select_db("tcs",$con);
  8. if(isset($_COOKIE['cookname']) && isset($_COOKIE['cookpass']))
  9. {
  10. $usr = $_COOKIE['cookname'];
  11. $pwd = $_COOKIE['cookpass'];
  12. $pwd=hash('sha1',$_POST['password']);
  13. }
  15. else
  16. {
  17. $usr=$_POST["username"];                 
  18. $pwd=hash('sha1',$_POST['password']);           
  19. }
  20. </code>
  21. Through this code I am checking is there any cookie with cookname and cookpassword which contain username and password. If no cookie is found with this name then retrieve username and password from textboxes directly, if the user enters them.
  23. Now the code which I am going to write will set a cookie if username and password exists:
  24. <code>
  25. if ($result) { $row=mysql_fetch_array($result);
  27. if (($row["Username"]==$usr) && ($row["Password"]==$pwd))
  28. {
  29.     if(isset($_POST['remember']))
  30.     {
  31.     setcookie("cookname", $row['Username'], time()+60*60*24*100, "/");
  32.     setcookie("cookpass", $row['Password'], time()+60*60*24*100, "/");
  33.     }
  36. $_SESSION['employee']['id']=$row['User Id'];
  37.     $_SESSION['employee']['username']=$row['Username'];
  39.     header ("Location: home_page.php");
  41. }
Now when starting, when I enter username and password and if these are right show a cookie must have been set and if now I am signed out and try the same sign in form, as according to me it should retrive cookie but nothing happining here. I am not able to implement it. Where am I going wrong?
Feb 1 '10 #1
4 2088
'Remember me' and 'Stay logged in' are two different things. when you log off the session is killed. Now, if you want to get automatically logged in you may have to store the session_id as well in the cookie and process it later in the program for this purpose.
Feb 2 '10 #2
1,044 Expert 1GB
@shabinesh: No and no. When you manually log off, the session is no longer authenticated as the user, but it is by no means destroyed. Even guest users have sessions. Also, you wouldn't just save the session ID in a cookie and reuse it. Firstly, sessions expire when they are inactive for a certain period of time. Secondly, this allows a user that finds this cookie to save that value in their own cookie and always access this account.

Anyway, refer to my response in another thread for how to accomplish this:
Feb 2 '10 #3
But in this thread solution is not given in this thread it is told that u should add an extra column in ur database to store login status.I dont know what should be stored there and how i can retrive this state at login page..Can i use all password matching php coading on login page also...plz explain little bit more for those guies who need some more explaiantion in form of code to grab concept...
Feb 2 '10 #4
1,044 Expert 1GB
The answer's given. I won't go more in-depth than that. I have given you the theory. The implementation is up to you.
Feb 2 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Joshua Beall | last post by:
Hi All, What is the best way to use a cookie to remember a logged in user? Would you store the username and password in two separate cookies? Should the password be plain text? Hashed? Not...
by: Kai Grossjohann | last post by:
I have a web app which comprises different frames: a menu bar frame, a search form frame, a result list frame. Depending on the state, only a subset of these frames is available. (Eg, after...
by: Grace | last post by:
Are there any ways it can let users only login once and users can browse different ASP.Net/ASP web applications on different machines? ex: A machine: login web application, a web application B...
by: Lee Wilkie | last post by:
Dear All, I'm new to ASP.NET and have been developing a small app at work to test Forms Authentication. When running on my development machine (using http://localhost/TestApp/Login.aspx for...
by: Shakun | last post by:
Hi All, This is my 1st posting to this group. Can any1 help me with the "Remember Me" which is there in a login form. Im pasting the code below. Im not able to set a cookie.. Thanks, Shakun...
by: Dabbler | last post by:
I have a login page which requires all users to login everytime they visit, the remember me feature isn't working. We all have cookies and js enabled. Any suggestions on how to diagnose this? ...
by: Kesavan | last post by:
Is there any way to run a function or a code-block whenever the client- server communication breaks off. (ie power-off, browser-crash...) Why I need this is, I want to update a login-table to...
by: Jon Slaughter | last post by:
I have developed a technique to add and remove cookies after output... wondering if there is something else like this out there? Jon
by: wazdakka | last post by:
I have an Access application developed using Access 2003 that I am trying to distribute. I have used the Package and Deployment Wizard that comes with the Office 2003 Developers Kit, and have been...
by: luqman | last post by:
If user login with the login control in ASP.Net 2005 and then just close the browser and then open the browser again, the login status shows, User still Login? Any idea, how to Logout the User...
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.