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
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 02-01-2008, 04:54 PM   #1 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default Problem xD

Why doesn't this work?

PHP Code:
                    if(!isset($uid)) {
                        
                        
$_SESSION['error'] = '<font color="red">We couldn\'t find a user using those login details!</font>';
                        if(isset(
$_SESSION['error'])) {
                            
                            
header("Location: account.php?act=login");
                            
                        }
                        
                        else {
                            
                            echo 
'Could not set session';
                            
                        }
                        
                    }
                    
                    else {
                        
                        
$tanaxia['user']->user_login($uid);
                        
                    } 
And then this in my loginform:
PHP Code:
                    $tanaxia['template']->loadfile('loginform');
                    
$msg $_SESSION['error'];
                    
$tanaxia['template']->parse(
                    
                    array(
                    
                        
'error' => array(
                        
                            
'msg' => $msg
                        
                        
)
                    
                    )); 
And this is loginform.tpl
Code:
			<h1>Login</h1>
			
			<form action="account.php?act=login" method="post">
			<h3>Username:</h3>
			<input type="text" name="user" /><br />
			
			<h3>Password:</h3>
			<input type="password" name="pass" /><br /><br />
			
			<input type="submit" name="login" value="Login" />
			</form>
			
			{error.msg}
I logged in with the wrong details just to test the error msg..
But it didn't work =//

The error msg didn't show.. it just redirected me to the loginform again..

Any ideas? :S
Tanax is offline  
Reply With Quote
Old 02-01-2008, 06:32 PM   #2 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Okey, I noticed something.
I tried to login with the correct details, and it still didn't work.

So here's the whole code:
PHP Code:
        case 'login':
        
            if(
$tanaxia['user']->user_is_logged_in()) {
                
                
header("Location: account.php?act=home");
                
            }
            
            else {
                
                if(isset(
$_POST['submit'])) {
                    
                    
$user $_POST['user'];
                    
$pass $_POST['pass'];
                    
                    
$uid $tanaxia['user']->user_check($user$pass);
                    
                    if(!isset(
$uid)) {
                        
                        
$_SESSION['error'] = '<font color="red">We couldn\'t find a user using those login details!</font>';
                        if(isset(
$_SESSION['error'])) {
                            
                            
header("Location: account.php?act=login");
                            
                        }
                        
                        else {
                            
                            echo 
'Could not set session';
                            
                        }
                        
                    }
                    
                    else {
                        
                        
$tanaxia['user']->user_login($uid);
                        
                    }
                    
                }
                
                else {
                    
                    include(
'header.php');
                    
                    
$tanaxia['template']->loadfile('loginform');
                    
$msg $_SESSION['error'];
                    
$tanaxia['template']->parse(
                    
                    array(
                    
                        
'error' => array(
                        
                            
'msg' => $msg
                        
                        
)
                    
                    ));
                    unset(
$_SESSION['error']);
                    
                    include(
'footer.php');
                    
                }
                    
            }
        
            
// Login
            
break; 
I know there's nothing wrong with the template class..
But here's the login methods used:
PHP Code:
        public function user_check($user_name$user_pass) {
            
            
$sql sprintf("    SELECT 
                                    `%s` 
                                FROM 
                                    `%s` 
                                WHERE 
                                    `%s` = '%s' AND `%s` = md5('%s')
                                LIMIT 1"

                                
                                
$this->db->col['user_id'],
                                
$this->db->table['users'],
                                
$this->db->col['user_name'],
                                
$user_name,
                                
$this->db->col['user_pass'],
                                
$user_pass);
                                
            
$query $this->db->query($sql);
            
            if(@
mysql_num_rows($query)) {
                
                
$user_info $this->db->fetch($query);
                
                return 
$user_info['user_id'];
                
            }
            
            else {
                
                return 
false;
                
            }
            
        }

        public function 
user_login($user_id) {
            
            
$sql sprintf("    UPDATE
                                    `%s`
                                SET
                                    `%s` = '%s',
                                    `%s` = NOW(),
                                    `%s` = NOW()
                                WHERE
                                    `%s` = '%d'"
,
                    
                                
$this->db->table['users'],
                                
$this->db->col['user_session'],
                                
session_id(),
                                
$this->db->col['user_last_visit'],
                                
$this->db->col['user_last_action'],
                                
$this->db->col['user_id'],
                                
$user_id);
                                
            
$this->db->query($sql);
            
        }

        public function 
user_is_logged_in() {
            
            
$sql sprintf("    SELECT
                                    `%s`
                                FROM
                                    `%s`
                                WHERE
                                    `%s` = '%s'
                                LIMIT 1"
,
                                
                                
$this->db->col['user_id'],
                                
$this->db->table['users'],
                                
$this->db->col['user_session'],
                                
session_id());
            
                            
            
$query $this->db->query($sql);
            
            if(@
mysql_num_rows($query)) {
                
                return 
true;
                
            }
            
            return 
false;
            
            
        } 
Edit: Yes I know I didn't secure it..
Tanax is offline  
Reply With Quote
Old 02-01-2008, 08:06 PM   #3 (permalink)
Alan @ CIT
Member of the Month
The Frequenter
Member of the Month Top Contributor 
 
Alan @ CIT's Avatar
 
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
Alan @ CIT is on a distinguished road
Default

I guess the first step would be to figure out where it is getting to in your script. Can you put some die()/var_dump() combo's in each of your if() checks to see which ones are running and whether they contain the variables you expected?

That should give us a clue as to what stage it is dying on.

Alan
Send a message via MSN to Alan @ CIT
Alan @ CIT is offline  
Reply With Quote
Old 02-06-2008, 08:16 AM   #4 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Quote:
Originally Posted by Alan @ CIT View Post
I guess the first step would be to figure out where it is getting to in your script. Can you put some die()/var_dump() combo's in each of your if() checks to see which ones are running and whether they contain the variables you expected?

That should give us a clue as to what stage it is dying on.

Alan
Actually, I solved it
I set the name of the login button to "login", and I checked for if($_POST['submit']), so obviously, I had to either change that to if($_POST['login']), or change the submit button to name="submit".

Anyways, thanks
__________________
Tanax is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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:27 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design