TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
Advertisement
Associates
Associates
techtuts Darkmindz
CSS Tutorials Tutorialsphere.com - Free Online Tutorials
Boston PHP SurfnLearn
Reply
 
LinkBack Thread Tools Display Modes
Old 06-24-2008, 09:04 AM   #1 (permalink)
The Visitor
Newcomer 
 
Join Date: May 2008
Posts: 1
Thanks: 0
anoopd is on a distinguished road
Default form for logged user

Hi Friends,

Im a newbie here . Just wanted to clear some of my doubts ... i am working with a site where the logged user can
edit something ... ie; a form should be shown only for logged users.. should i use iframes or just show the php file checking session ...Expecting valuable advice and thanks in advance

Anoop
anoopd is offline  
Reply With Quote
Old 06-24-2008, 12:25 PM   #2 (permalink)
Jim
The Addict
 
Jim's Avatar
 
Join Date: Nov 2007
Location: the Netherlands
Posts: 224
Thanks: 2
Jim is on a distinguished road
Default

Just create a function (like isLoggedIn()) returning true or false. In that function check the session and maybe some more proof to be 100% sertain the user is logged in.

Something like this will be the result:

PHP Code:
<?php

if(isLoggedIn()) {

   
// Parse form

} else {

   echo 
'Not logged in';

}

?>
How this helps a bit :)
Send a message via MSN to Jim Send a message via Skype™ to Jim
Jim is offline  
Reply With Quote
Old 06-24-2008, 03:30 PM   #3 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 1,542
Thanks: 72
Wildhoney is on a distinguished road
Default

Perhaps having a peruse over this script that I did may be of some use to you?
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is online now  
Reply With Quote
Old 06-25-2008, 09:50 AM   #4 (permalink)
The Acquainted
 
Join Date: Oct 2007
Posts: 126
Thanks: 12
maZtah is an unknown quantity at this point
Default

Yesterday I've written this function to check whether a user is logged in or not:

Users have options to save their login in a cookie, so that they don't have to fill the login form back in again.

A cookie is stored like: 'username;sha1hashedpasswordwithoutsalt'.

PHP Code:
// You have to define a SALT first
define('SALT''foo');

function 
is_logged_in()
{
    if (isset(
$_COOKIE['user']))
    {
        list(
$szName$szPassword) = explode(';'$_COOKIE['user']);
        
        
$szQuery sprintf(
            
"SELECT id
                FROM users
                WHERE name = '%s' AND password = SHA1(CONCAT('%s', '%s'))
                LIMIT 1"
$szNameSALT$szPassword);
        
        
$pUser mysql_query($szQuery) or die(mysql_error());
        
        if (
mysql_numrows($pUser) > 0)
        {
            return 
TRUE;
        }
    }
    elseif (
$_SESSION['loggedin'] === 1)
    {
        return 
TRUE;
    }
    else
    {
        return 
FALSE;
    }

Then, you can check (just like Jim did) if a user is logged in like so:

PHP Code:
if (is_logged_in() === TRUE)
{
    echo 
'Logged in.';
}

// Or

if (is_logged_in() !== TRUE)
{
    echo 
'Not logged in.';

Good luck!
maZtah is offline  
Reply With Quote
Old 06-25-2008, 09:53 AM   #5 (permalink)
Jim
The Addict
 
Jim's Avatar
 
Join Date: Nov 2007
Location: the Netherlands
Posts: 224
Thanks: 2
Jim is on a distinguished road
Default

Even if it's hashed with a salt, never save a password in a Cookie.
Send a message via MSN to Jim Send a message via Skype™ to Jim
Jim is offline  
Reply With Quote
Old 06-25-2008, 09:58 AM   #6 (permalink)
The Acquainted
 
Join Date: Oct 2007
Posts: 126
Thanks: 12
maZtah is an unknown quantity at this point
Default

I think you are true on that. What's a better way to store a cookie (and to check if it's from a real logged in user)?
maZtah is offline  
Reply With Quote
Old 06-25-2008, 10:05 AM   #7 (permalink)
Jim
The Addict
 
Jim's Avatar
 
Join Date: Nov 2007
Location: the Netherlands
Posts: 224
Thanks: 2
Jim is on a distinguished road
Default

What i always do is make an SQL table:

id - ipadres - userid - uniquestring
1 - 127.0.0.1 - 1 - bvt54345bw45herw45vw45wgef

And save a cookie named "login" or something containing the uniquestring. Then check the table for a record containing the uniquestring and ipadres. And then if its found login the user since you have it's userid.

Although i use this for autologin, you can also check it for login validation.
Send a message via MSN to Jim Send a message via Skype™ to Jim
Jim is offline  
Reply With Quote
Old 06-25-2008, 10:10 AM   #8 (permalink)
The Acquainted
 
Join Date: Oct 2007
Posts: 126
Thanks: 12
maZtah is an unknown quantity at this point
Default

Yep that's definitely a better route to go. Well, I think anoopd should be able modify my script to make it work like that. If not, I will post an update later.

Thanks for keeping me sharp, Jim!
maZtah is offline  
Reply With Quote
Reply



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

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


All times are GMT. The time now is 06:46 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0