Programming Tools
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingProgramming Tools

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 15th, 2002, 02:54 AM
wAr-AnGeL wAr-AnGeL is offline
Forum Security
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Behind You
Posts: 479 wAr-AnGeL User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m 50 sec
Reputation Power: 17
Send a message via ICQ to wAr-AnGeL Send a message via AIM to wAr-AnGeL
Question Using cookies with forms

I have a basic authentication script using PHP to verify username & password from a MySQL db. How could I make it so the users would not need to login everytime and a cookie could just save their info?
__________________




"Only Linux users see the end of crashes."
- Pl4t0

Reply With Quote
  #2  
Old April 15th, 2002, 04:32 AM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
ive never tried to program username remebers using cookies before, but im guessing it would go something like this

when the user is accepted by the submit form, if the password and username is checked and passed, a cookie is created with the usernames 'name' (hehe bad joke!) when the comeback to the login form again, in the header of the script check to see if theres a cookie, if so check the value of the cookie against the database, if correct, auto login!

anyways thats how i would do it, if you wanted to be more secure you could encrypt the password, and store that as a cookie as well

Reply With Quote
  #3  
Old April 15th, 2002, 09:34 AM
mytch mytch is offline
Dev Articles Novice (500 - 999 posts)
 
Join Date: Apr 2002
Location: Sydney, Australia
Posts: 588 mytch User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 17
Hi,
Ben's right, and here's the code you need. Firstly, for the login form:

<?php

global $HTTP_COOKIE_VARS;

if($HTTP_COOKIE_VARS["auth"] == true)
{
header("some_other_page.php");
}
else
{
?>

<form action="checklogin.php" method="post">
User: <input type="text" name="user"><br>
Password <input type="password" name="pass"><br>
<input type="submit">

<?php

}

?>

and for checklogin.php:

// do you database stuff here, i will assume you've created
// a variable called $ok which is the result of a call to
// mysql_num_rows("select * from logins where user=...") etc

if($ok == true)
{
setcookie("auth", true);
header("some_other_page.php");
}
else
{
header("location: login.php");
}

that should get you started, let me know if you need more help

Reply With Quote
  #4  
Old April 15th, 2002, 10:13 AM
wAr-AnGeL wAr-AnGeL is offline
Forum Security
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Behind You
Posts: 479 wAr-AnGeL User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m 50 sec
Reputation Power: 17
Send a message via ICQ to wAr-AnGeL Send a message via AIM to wAr-AnGeL
thx for the code, i'll try it

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingProgramming Tools > Using cookies with forms


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap