General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

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 22nd, 2003, 05:11 PM
Mary Mary is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 59 Mary User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 5 m 17 sec
Reputation Power: 0
Question Remember Login???

Currently, I am working on the Members Area, such as members login, the script will generate a sessionid for this member. And I am trying to create a script that can remember members info if a member checked the checkbox when he/she logged in the site, so that everytime he/she comes to the site he/she will be automately login. Could somebody help me with this? What steps I have to do? Greatly appreciated.

Reply With Quote
  #2  
Old April 22nd, 2003, 06:53 PM
avit avit is offline
Not Yet Perfect
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: Squamish, BC
Posts: 111 avit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to avit
What you have to do is set a cookie on the client's browser that is returned to you when they request a page. That way you can identify their SID.

Look here:

http://www.onlamp.com/pub/a/php/excerpt/webdbapps_8/

Reply With Quote
  #3  
Old April 22nd, 2003, 07:17 PM
avit avit is offline
Not Yet Perfect
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: Squamish, BC
Posts: 111 avit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to avit
Better yet, look right on this site:

http://www.devarticles.com/art/1/285/1

Reply With Quote
  #4  
Old April 22nd, 2003, 10:56 PM
wareseeker wareseeker is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 71 wareseeker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 7 sec
Reputation Power: 6
I have no idea. You're better read more about cookies.

Reply With Quote
  #5  
Old April 22nd, 2003, 11:02 PM
Mary Mary is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 59 Mary User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 5 m 17 sec
Reputation Power: 0
Thanks for your help Avit. It is really hard for me to implement my code in to Ben's Article, because I designed my code different than Ben's Codes. Here is the brief login procedures that I have coded so far if anyone can help me I would greatly appreciate:

Quote:
index.php -> login and save cookie.

//==== session vars created
$_SESSION["session"]["login"]=$login;
$_SESSION["session"]["password"]=$pass;
$_SESSION["session"]["loggedIn"]=true;

//==== cookie stored
if($_POST['strSetCookie'] == 1) {
mysql_query("UPDATE users SET sessionid = '" . session_id() . "' WHERE login = '$login'");
setcookie("bakecookie", session_id(), time()+(3600*24*30*4));


From this point, I have no idea how to setup a check cookie and other steps in order the cookie to be recognized. Please someone help me with this.

Reply With Quote
  #6  
Old April 23rd, 2003, 12:33 AM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 366 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 30 m 59 sec
Reputation Power: 7
PHP Code:
// We need to check to see if a cookie is set.
// If the session var "se_UID" is NOT set and a cookie var IS set, then we need to check out his id_hash and check to see if he is a valid user.
// If he is a valid user, we need to set all session vars for him.

// Let's walk through step by step.
if(!isset($_SESSION['se_UID']) && isset($_COOKIE['c_uid']) && isset($_COOKIE['id_hash']))
// is there a session already started?  does a cookie id exist?
{
     
$sql_checkUser mysql_query("SELECT UID, U_HASH FROM users WHERE UID = '{$_COOKIE['c_uid']}' AND U_HASH = '{$_COOKIE['id_hash']}' LIMIT 1"$id_link);
     
// there was a cookie var for this user, so we select his user id and password and compare them to the cookie.
     
     
if(mysql_num_rows($sql_checkUser) == 1)
     
// if the 2 match up then, (go to next lines)
     
{
          
$sql mysql_query("SELECT UID, U_NICK, FK_CSS_ID, U_LOGIN, U_ADMIN, U_NEWSADMIN, U_FADMIN, U_NUM_ROWS, U_LASTLOGIN, U_F_LASTLOGIN, U_HASH FROM users WHERE UID = '{$_COOKIE['c_uid']}' AND U_HASH = '{$_COOKIE['id_hash']}' LIMIT 1"$id_link);
          
// select all fields needed for session vars.
          
if(mysql_num_rows($sql) == 1)
          {
                 
// load db vars into session array.
               
$row_session mysql_fetch_array($sql$id_link);

               
$_SESSION['se_UID']           = $row_session['UID'];
               
$_SESSION['se_LOGIN']         = $row_session['U_LOGIN'];
               
$_SESSION['se_NICK']          = $row_session['U_NICK'];
               
$_SESSION['se_ADMIN']         = $row_session['U_ADMIN'];
               
$_SESSION['se_FADMIN']        = $row_session['U_FADMIN'];
               
$_SESSION['se_NEWSADMIN']     = $row_session['U_NEWSADMIN'];
               
$_SESSION['se_NUM_ROWS']      = $row_session['U_NUM_ROWS'];
               
$_SESSION['se_LASTLOGIN']     = $row_session['U_LASTLOGIN'];
               
$_SESSION['se_F_LASTLOGIN']   = $row_session['U_F_LASTLOGIN'];
          }
     }

__________________
-- Jason

Last edited by Taelo : April 23rd, 2003 at 01:42 AM.

Reply With Quote
  #7  
Old April 23rd, 2003, 01:33 AM
Mary Mary is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 59 Mary User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 5 m 17 sec
Reputation Power: 0
Thank you very much Jason! But how can I use it? I have no clue with your code. Could you give a instruction? Thanks again.

Reply With Quote
  #8  
Old April 23rd, 2003, 01:43 AM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 366 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 30 m 59 sec
Reputation Power: 7
I edited and added comments,...let me know if it helps,..

Reply With Quote
  #9  
Old April 23rd, 2003, 02:14 AM
avit avit is offline
Not Yet Perfect
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: Squamish, BC
Posts: 111 avit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to avit
Quote:
Originally posted by Taelo
PHP Code:
// We need to check to see if a cookie is set.
// If the session var "se_UID" is NOT set and a cookie var IS set, then we need to check out his id_hash and check to see if he is a valid user.
// If he is a valid user, we need to set all session vars for him. 



Back up a little for me too, Taelo...

What's the id_hash ? Is that an md5() of the uid & pass?
Do you store that using setcookie(), and then compare it to a stored hash in your database?

Reply With Quote
  #10  
Old April 23rd, 2003, 12:02 PM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 366 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 30 m 59 sec
Reputation Power: 7
this can be anything,....... it can be an md5 password,... or md5 session id,..... anything really,...... the point is to have more then 1 cookie ID to authenticate against. that way it makes it harder for a user to "become" another user

just make sure to that whatever you choose to set in the cookie, set it in the database as well

Reply With Quote
  #11  
Old April 23rd, 2003, 01:09 PM
Mary Mary is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 59 Mary User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 5 m 17 sec
Reputation Power: 0
Thanks for your kind help, but I couldnot figure it out how to apply to the code which I currently have into yours. Could you please help if I sent you my codes. Greatly appreciated.

Reply With Quote
  #12  
Old April 23rd, 2003, 01:24 PM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 366 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 30 m 59 sec
Reputation Power: 7
the easiest way to do it,....is to throw my code into a function or put it into a file and include it on a page. just remember the steps you need to take

1.) check to see if any session vars exist
2.) check their cookie values against their database values
3.) if they match, reset this users session vars


ohhh yeah, I am sure you already knew this, but you are going to have to change some things, well alot of things, if you want to use my code. I was just showing a flow and how I do it.

Reply With Quote
  #13  
Old April 23rd, 2003, 03:57 PM
Mary Mary is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 59 Mary User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 5 m 17 sec
Reputation Power: 0
I give up. Cann't do it. Please help Taelo.

Reply With Quote
  #14  
Old April 23rd, 2003, 08:05 PM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 366 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 30 m 59 sec
Reputation Power: 7
hehehe,....post your login code,.....not the html form,...just the php.

Reply With Quote
  #15  
Old April 24th, 2003, 12:58 AM
Mary Mary is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 59 Mary User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 5 m 17 sec
Reputation Power: 0
Smile

Yessss!!!! Finally, You accept to help me. Honestly, I was so disappointed that you was not gonna help me. Now, I am so happy . You're my man.

Here I have enclosed some parts of my code and how I designed. Please don't laugh about my code. I am just a newbie .
I am willing to fix anything from database design to any parts of my project. Once again, thanks you so much for you help.
Attached Files
File Type: txt code.txt (3.4 KB, 350 views)

Reply With Quote
  #16  
Old April 24th, 2003, 01:31 AM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 366 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 30 m 59 sec
Reputation Power: 7
here are the pieces of your code you need to be concerened with

PHP Code:
// if we got here, no errors - start a session using the info
    // returned from the db:
    
cleanMemberSession($row[login], $row[password]);