472,353 Members | 1,510 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 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());
  5.  
  6. mysql_select_db("tcs",$con);
  7.  
  8. if(isset($_COOKIE['cookname']) && isset($_COOKIE['cookpass']))
  9. {
  10. $usr = $_COOKIE['cookname'];
  11. $pwd = $_COOKIE['cookpass'];
  12. $pwd=hash('sha1',$_POST['password']);
  13. }
  14.  
  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.
  22.  
  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);
  26.  
  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.     }
  34.  
  35.  
  36. $_SESSION['employee']['id']=$row['User Id'];
  37.     $_SESSION['employee']['username']=$row['Username'];
  38.  
  39.     header ("Location: home_page.php");
  40.  
  41. }
  42.  
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 2045
'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
kovik
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:
http://bytes.com/topic/php/answers/8...on#post3541792
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
kovik
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

15
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? ...
13
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...
2
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...
2
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...
2
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....
1
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...
7
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...
4
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
4
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...
20
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...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

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.