Current location: Hot Scripts Forums » Programming Languages » PHP » how to check SESSION is valid


how to check SESSION is valid

Reply
  #1 (permalink)  
Old 05-17-09, 01:35 PM
macintosh macintosh is offline
Newbie Coder
 
Join Date: Mar 2007
Posts: 84
Thanks: 1
Thanked 0 Times in 0 Posts
how to check SESSION is valid

After user has given username and password , i use following way to check login and set session...

PHP Code:

<?php 

session_start
(); 

$result mysql_query("SELECT * from login WHERE name='" $_POST['name'] . "' AND password='" $_POST['password'] . "'"); 

$rows=mysql_mun_rows($result);

if (
$rows 0


session_register('name');
$_SESSION['name'] = $_POST['name'];

header("Location: success.php");
exit; 
}  else { 

//unsuccessful login 
header("Location: login.php");
exit; 


?>
My question is that, when do i need to put password also in session???
How do i check if the session is valid or not ? eg. for example there is some name value in session, do i have to check from db it there is any user with this name + password? or there is some other way?

thank you very much for your time.
Reply With Quote
  #2 (permalink)  
Old 05-17-09, 07:02 PM
landing's Avatar
landing landing is offline
Coding Addict
 
Join Date: Jul 2006
Location: Scotland
Posts: 302
Thanks: 0
Thanked 0 Times in 0 Posts
You shouldn't need to store the password in the session really (unless of course you want to be able to forcefully log a user out). The session is valid because you have checked the users log in details before assigning the particular 'name' session variable. As long as 'name' is set, the user has logged in. And it's only valid for as long as the user has their browser open.

There is a security concern known as session hijacking (Google it). However, you are far more at risk for performing database queries on unsanitised form input. See the link in my signature.
__________________
Always sanitise your data


Best regards
Reply With Quote
Reply

Bookmarks

Tags
login, php, session


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
destroy a session on different domain Deansatch PHP 4 07-31-08 04:19 AM
Prevent multiple logins using session id ramush PHP 2 07-01-08 12:46 PM
Session Security (Continued from post below) nova912 PHP 1 09-05-06 09:29 AM
Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')' Dr. Forensics PHP 3 07-15-06 03:54 PM
urgent: session timeout occurs unexpectedly in ASP.net seemagaur ASP.NET 3 10-11-05 11:10 PM


All times are GMT -5. The time now is 08:36 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.