[Tutorial] Creating a basic user control panel
#16

PHP Code:
<input type='submit' name="submit" value='Login' /> 
$submit $_POST['submit']; //variable for submit button, in this variable we save button that player press in <input type='submit' name="submit" value='Login' />.... 
Why in the world do you need a submit variable it doesn't store any result

PHP Code:
if($submit//if he press submit button 
{     
    if(
$username && $password//if he type both of username and password not just one of them 
    

        
$query mysql_query("SELECT username, password FROM users WHERE username = '$username'"); //selecting user name and password, change it to your field names,  chage users to your table name, $username means username that he type... 
        
if(mysql_num_rows($query) == 1//if user exists 
        

            while(
$row mysql_fetch_assoc($query)) //loop thought table that we select in mysql_query 
            

                
$dbusername $row['username']; //setting dbusername as variable from table, change 'username' to your field! 
                
$dbpassword $row['password']; //setting dbpassword as variable from table, change 'password' to your field! 
            

            if(
$username == $dbusername && $password == $dbpassword//if username is same as one from table and if password is the same as one from table... 
            

                
$_SESSION['username'] = $dbusername//setting session username to one from table, this is useful if you login, that restart your browser and than you go in url where is your profile.php... Anyway this is useful :D 
                
echo header('location: profile.php'); //redirecting user to his profile page (profile.php) 
            

            else echo 
"Wrong password!"//else if user type wrong password he will get this... 
        

        else echo 
"Username doesn't exist!"//if username doesn't exist in table user will get this 
    

    else echo 
"Type name and password!"//else if user doesn't type all fields he will get this... 

You are doing it the messed way, "SELECT username, password from users WHERE username = {$username} AND password = {$password}" would do it.

PHP Code:
if($username == $dbusername && $password == $dbpassword

       
session_regenerate_id();// create another session id to prevent from session fixation.
       
$_SESSION['username'] = $dbusername// From here it's vulnerable to session fixation.
       
header('location: profile.php'); 

Use Jquery plugins like Flowtools form validator, they are easy to explain and validate form.
Reply


Messages In This Thread
Creating a basic user control panel - by System64 - 17.10.2011, 09:00
Re: Creating a basic user control panel - by Lorenc_ - 17.10.2011, 09:25
Re: Creating a basic user control panel - by Sinner - 17.10.2011, 09:28
Re: Creating a basic user control panel - by System64 - 17.10.2011, 09:29
Re: Creating a basic user control panel - by Sinner - 17.10.2011, 09:31
Re: Creating a basic user control panel - by System64 - 17.10.2011, 09:39
Re: Creating a basic user control panel - by [HiC]TheKiller - 17.10.2011, 09:42
Re: Creating a basic user control panel - by System64 - 17.10.2011, 10:02
Re: Creating a basic user control panel - by Lorenc_ - 17.10.2011, 10:17
Re: Creating a basic user control panel - by System64 - 17.10.2011, 10:19
Re: Creating a basic user control panel - by GloomY - 17.10.2011, 10:20
Re: Creating a basic user control panel - by System64 - 17.10.2011, 10:33
Re: Creating a basic user control panel - by System64 - 17.10.2011, 18:21
Re: Creating a basic user control panel - by Baboon - 17.10.2011, 20:25
Re: Creating a basic user control panel - by System64 - 17.10.2011, 20:27
Re: Creating a basic user control panel - by XFlawless - 18.10.2011, 10:46
Re: Creating a basic user control panel - by System64 - 18.10.2011, 11:05
Re: Creating a basic user control panel - by XFlawless - 18.10.2011, 12:59
Re: Creating a basic user control panel - by System64 - 18.10.2011, 17:49
Re: Creating a basic user control panel - by DiNorscio - 05.04.2012, 09:23
Re: Creating a basic user control panel - by System64 - 05.04.2012, 09:34
Re: Creating a basic user control panel - by Krunsy - 21.04.2012, 11:32
Re: Creating a basic user control panel - by System64 - 21.04.2012, 13:08
Re: Creating a basic user control panel - by Krunsy - 23.04.2012, 12:46
Re: Creating a basic user control panel - by Ballu Miaa - 23.04.2012, 17:53
Re: Creating a basic user control panel - by System64 - 23.04.2012, 19:58
Re: Creating a basic user control panel - by tiernantheman - 23.04.2012, 20:00
Re: Creating a basic user control panel - by Elysian` - 23.04.2012, 21:51
Re: Creating a basic user control panel - by Ballu Miaa - 24.04.2012, 02:39
Re: Creating a basic user control panel - by System64 - 24.04.2012, 12:08
Re: Creating a basic user control panel - by Claude - 24.04.2012, 15:58
Re: Creating a basic user control panel - by System64 - 24.04.2012, 16:36
AW: Creating a basic user control panel - by xOFxK1LLER - 25.04.2012, 15:32
Re: Creating a basic user control panel - by 3ventic - 26.04.2012, 16:10
Re: Creating a basic user control panel - by Ballu Miaa - 26.04.2012, 16:21
Re: Creating a basic user control panel - by SwiftKidZ - 02.05.2012, 04:12
Re: Creating a basic user control panel - by Gertin - 02.05.2012, 11:11
Re: Creating a basic user control panel - by System64 - 02.05.2012, 11:20
Re: Creating a basic user control panel - by Sanady - 28.09.2012, 14:13
Re: Creating a basic user control panel - by marine - 29.09.2012, 18:06
Re: Creating a basic user control panel - by Mikkel - 08.10.2012, 11:18
Re: Creating a basic user control panel - by ZackBoolaro - 08.10.2012, 11:29
Re: Creating a basic user control panel - by Roel - 25.10.2012, 06:59
Re: Creating a basic user control panel - by gtakillerIV - 25.10.2012, 12:33
Re: Creating a basic user control panel - by Dugzor - 30.09.2013, 20:18
Re: Creating a basic user control panel - by DanishHaq - 30.09.2013, 20:24
Re: Creating a basic user control panel - by logoster - 01.12.2013, 18:04
Re: Creating a basic user control panel - by BizzyD - 01.12.2013, 18:14
Re: Creating a basic user control panel - by thefatshizms - 01.12.2013, 22:16
Re: Creating a basic user control panel - by System64 - 06.12.2013, 19:43
Re: Creating a basic user control panel - by FahadKing07 - 12.12.2013, 20:40
Re: Creating a basic user control panel - by DavidLuango - 13.12.2013, 05:42
Re: Creating a basic user control panel - by Spydah - 21.03.2014, 21:22
Re: Creating a basic user control panel - by Micko123 - 10.05.2016, 06:56
Re: Creating a basic user control panel - by Zorono - 02.06.2016, 18:37
Re: Creating a basic user control panel - by Zeus666 - 25.07.2016, 17:22

Forum Jump:


Users browsing this thread: 1 Guest(s)