The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 7 of 7

Thread: Taking me login form to another level [php]

  1. #1

    Taking me login form to another level [php]

    Well, Hello again php gurus!

    what im trying to get here is to adapt my current login forms check.php file so it can use member levels

    for example
    0 = guest
    1 = member
    2 = admin

    if someone logs in with the level 2 they will be taken to admin.php and so forth...

    Here is my currect check.php file :
    PHP Code:
    <?php
    include('../config/config.php');

    // Connect to server and select databse.
    $connect mysql_connect("$dbhost""$dbuser""$dbpass")or die("cannot connect");
    mysql_select_db("$dbname")or die("cannot select DB");

    // username and password sent from signup form
    $myusername=$_POST['myusername'];
    $in=$_POST['mypassword'];

    $symb = array("$""=""*""%""\";"");");
    $pass str_replace($symb""$in);
    $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$pass'";
    $result=mysql_query($sql);


    // Mysql_num_row is counting table row
    $count=mysql_num_rows($result);
    // If result matched $myusername and $mypassword, table row must be 1 row
    if($count==1){

    // Register $myusername, $mypassword and redirect to file "login_success.php"
    session_register("myusername");
    session_register("mypassword");
    header("location:admin.php");
    }
    else {
    header("location:task.php?status=0");
    }
    ?>
    Thank you!!!
    My Photography
    Twitter

    K-Emmys-06: Best "Newbie"

  2. #2
    ummm in your user table just add a "level" column... then on your else statement do something like
    PHP Code:
    ...
    else { 
    $row['level'] == ) ? header("location:admin.php") : header(location:task.php?status=0); 
    }
    ... 
    and then of course when you're someone access the admin.php page you'll need to check for their session, and their user permission again...
    PHP Code:
    if ( $row['level'] != header("location:index.php"); 
    Let us live so that when we come to die even the undertaker will be sorry. - Mark Twain
    Don't PM me your CSS, xHTML, JS or PHP questions. I will not reply to ANY IE6 questions.

  3. #3
    Its giving me this error

    its redirected to the task.php page for the incorrect username & password

    wha? and why?
    My Photography
    Twitter

    K-Emmys-06: Best "Newbie"

  4. #4
    Well I have no clue what "this error" is. And it's prolly redirecting cause the person logging in isn't at an admin level. All I did was give you the concept behind it, so I'm sure if you copied it verbatim it's not gonna work exactly right.
    Let us live so that when we come to die even the undertaker will be sorry. - Mark Twain
    Don't PM me your CSS, xHTML, JS or PHP questions. I will not reply to ANY IE6 questions.

  5. #5
    oops, typo...

    The problem is that it redirects to the task.php page.
    but the user is at admin level...

    Ill try again
    My Photography
    Twitter

    K-Emmys-06: Best "Newbie"

  6. #6
    Well a few things...

    first... the way you're registering your sessions is antiquated, depreciated and no good
    PHP Code:
    session_register("myusername");
    session_register("mypassword"); 
    should be
    PHP Code:
    $_SESSION['myusername'] = $myusername
    $_SESSION
    ['mypassword'] = $in 
    http://us.php.net/manual/en/function...n-register.php
    but only after the condition of it being a valid login is correct. currently your script doesn't even look like it's storing "mypassword" anyway since there is no $mypassword variable.

    second... you need to start the session before you can even register anything into a session
    PHP Code:
    session_start(); 
    should be the first line of your script

    None of these does it look like you're doing


    third, on all your pages you need to compare the user and password... and possibly the user's id on all pages, check their permission and based on all those criteria you need to redirect to the appropriate pages.
    Let us live so that when we come to die even the undertaker will be sorry. - Mark Twain
    Don't PM me your CSS, xHTML, JS or PHP questions. I will not reply to ANY IE6 questions.

  7. #7
    alllooo...
    just want to ask...
    how i want to do coding login level user...
    this is my coding...please anyone help me....

    <?php

    include 'config.php';

    $accessLevels = array("1");
    $validLevel = $_SESSION[''];

    if(!empty($_POST['username']) && !empty($_POST['password']))
    {
    $user_info = auth_user($_POST);
    if($user_info)
    {
    $_SESSION['auth'] = true;
    $_SESSION['username']=$user_info['username'];
    $_SESSION['level'] = $user_info['level'];
    check_login();
    }
    else
    //if statement untuk level Header("Location: index.php");
    if (array_search($accessLevels,$validLevel)>-1)
    {
    Header("Location: index.php");
    } else
    if (array_search($accessLevels,$validLevel)>-2)
    {
    Header("Location: permohonan_dekan.php");
    }
    else



    {
    echo 'Username/Password Salah';
    }

    }
    include 'templates/login_form.html';

    ?>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012