Results 1 to 12 of 12

Thread: [RESOLVED] Authentication Function HELP

  1. #1

    Thread Starter
    Hyperactive Member PlaGuE's Avatar
    Join Date
    Jun 2005
    Location
    in ur mind.
    Posts
    445

    Resolved [RESOLVED] Authentication Function HELP

    Well recently i took upon a task.Which needed me to make an authentication function/system for it, and well.... i thought i'd go into an old project and use that one.... but.... then i found out... that my sister had gotten onto the computer and DELETED ALL OF MY PROJECTS!!!!!!!!!!!!!!!!!!!!

    sooo...here i am.lol

    My problem is this.
    I am trying to create an authentication system.Pretty basic explanation i know.
    When your not logged in. It works fine.But...
    For some reason when i use this code in my index.php page(Shown below).
    To determine if the user should be able to view the page(when logged in) or not. It will show the "You do not have a high enough rank to view this page."
    aswell as the content that shouldnt be able to be viewed by the user.

    Here Are the files.
    Config.php Not included As it's just the SQL connection.Atm.

    Index.php
    PHP Code:
    <?php
    session_start
    ();
    require(
    "functions.php");

    if(
    Authentication(5)){
    print(
    "Welcome");
    }
    ?>
    I remember at least this much.On how to call the function in the index.php.

    this is my functions.php page
    PHP Code:
    <?php
    include("config.php"); //Includes the connection to the database
    error_reporting(E_ALL ^E_WARNING ^E_NOTICE);

    // Start Authentication Functions    
        
    function Authentication($mRank){
            
    // Authentication Functrion
            
    if(isset($_POST['AuthLogin'])){

                
    $result mysql_query("SELECT * FROM users WHERE username='".$_POST['userName']."' AND password='".$_POST['passWord']."'");
                          
    extract($userinfo mysql_fetch_object($result));
                            
    $_SESSION['CuSeR']    =    $userinfo->username;
                            
    $_SESSION['CuSeR_ID']    =    $userinfo->ID;
                            
    $_SESSION['CuSeR_Rank']    =    $userinfo->rank;
                            
    $_SESSION['CuSeR_LastLogin']    =    $userinfo->lastlogin;
            
            }        
    //*                
            
    $result mysql_query("SELECT * FROM users WHERE username='".$_SESSION['CuSeR']."'");
            
    extract($userinfo mysql_fetch_object($result));
                
                print(
    "My Rank:".$userinfo->rank."<br />");
                print(
    "Needed Rank:".$mRank."<br />");
                
                if(
    $userinfo->rank >= $mRank){
                        
    //return true;
                        
    if(!$userinfo->ID){
                            
    //return false;
                            
    return loginForm();
                        }
                    }else{
                        
    //return false;
                        
    return print("You do not have a high enough rank to view this page.<br />\n");
                        
                    }            

        }
    //End Authentication Function
        
        
    function loginForm(){
            
    ?>
            <form action="index.php?module=Login" name="AuthLoginForm" method="post">
            <table width="15%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#000000">
      <tr>
        <td colspan="2" bgcolor="#999999"><div align="center">Login</div></td>
        </tr>
      <tr>
        <td width="8%" bgcolor="#999999">Username</td>
        <td width="92%" bgcolor="#999999"><input name="userName" type="text" value="UserName" class="login_text" /></td>
      </tr>
      <tr>
        <td bgcolor="#999999">Password</td>
        <td bgcolor="#999999"><input name="passWord" type="password" value="Password" class="login_text" /></td>
      </tr>
      <tr>
        <td colspan="2" bgcolor="#999999"><div align="center">
          <input type="submit" name="AuthLogin" value="Submit" />
        </div></td>
        </tr>
    </table>

            </form>
            <?        
        }
        
    ?>
    Any Help is apperciated.
    Not to put any pressure on anyone but.. i have till saturday to finish.
    I had this project sprung on me without notice.T'is hard to say no. You know...
    Last edited by PlaGuE; Aug 23rd, 2006 at 11:46 PM.
    Without balance, there could only be chaos.
    Without chaos, there could be no balance.
    I live with karma. Eat with destiny. Dream of life without shackles....
    Yet. If life had no consequences, life could not exist, nor could it flourish.


    If at first you dont succeed.You're screwed.

    C++/Java NOOB.

    I aint a professional at PHP, but if i can help i will.

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Authentication Function HELP

    print always returns 1. Unless that's what you meant, it's almost certainly your source of error.

    And your loginForm function doesn't return anything, yet you're returning its non-existant result.

  3. #3

    Thread Starter
    Hyperactive Member PlaGuE's Avatar
    Join Date
    Jun 2005
    Location
    in ur mind.
    Posts
    445

    Re: Authentication Function HELP

    lol... i honestly didnt know that print returned 1...

    koo.
    Without balance, there could only be chaos.
    Without chaos, there could be no balance.
    I live with karma. Eat with destiny. Dream of life without shackles....
    Yet. If life had no consequences, life could not exist, nor could it flourish.


    If at first you dont succeed.You're screwed.

    C++/Java NOOB.

    I aint a professional at PHP, but if i can help i will.

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Authentication Function HELP

    Like pena said, print will always return true. Your problem lies here:
    PHP Code:
                if($userinfo->rank >= $mRank){
                        
    //return true;
                        
    if(!$userinfo->ID){
                            
    //return false;
                            
    return loginForm();
                        }
                    }else{
                        
    //return false;
                        
    return print("You do not have a high enough rank to view this page.<br />\n");
                        
                    } 
    If the rank is okay, the function doesn't return a value. A function which doesn't return a value, returns null and null is false. Don't return the vlaues of the loginform() and print() fucntions, call them first then return on the nextl ine:

    PHP Code:
                if($userinfo->rank >= $mRank){
                        
    //return true;
                        
    if(!$userinfo->ID){
                            
    //return false;
                            
    loginForm();
                            return 
    false;
                        } else {
                            return 
    true;
                        }
                    }else{
                        
    //return false;
                        
    print("You do not have a high enough rank to view this page.<br />\n");
                        return 
    false;
                        
                    } 
    Also, don't shoot yourself in the foot by turning off error reporting.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  5. #5

    Thread Starter
    Hyperactive Member PlaGuE's Avatar
    Join Date
    Jun 2005
    Location
    in ur mind.
    Posts
    445

    Re: Authentication Function HELP

    Also, don't shoot yourself in the foot by turning off error reporting.
    Im only turning off Warnings and Notices. As i dont care about those at the present time.
    Without balance, there could only be chaos.
    Without chaos, there could be no balance.
    I live with karma. Eat with destiny. Dream of life without shackles....
    Yet. If life had no consequences, life could not exist, nor could it flourish.


    If at first you dont succeed.You're screwed.

    C++/Java NOOB.

    I aint a professional at PHP, but if i can help i will.

  6. #6
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: [RESOLVED] Authentication Function HELP

    Warnings and notices are the most important during development stages. With them off you can miss errors which could take an age to find.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  7. #7

    Thread Starter
    Hyperactive Member PlaGuE's Avatar
    Join Date
    Jun 2005
    Location
    in ur mind.
    Posts
    445

    Re: [RESOLVED] Authentication Function HELP

    True.
    But like i said.I didnt need it on at the present time.(Now i have full error reporting on.)
    The only errors i ever got were "Undefined Variables ****..." because of my $_POST variables.
    Without balance, there could only be chaos.
    Without chaos, there could be no balance.
    I live with karma. Eat with destiny. Dream of life without shackles....
    Yet. If life had no consequences, life could not exist, nor could it flourish.


    If at first you dont succeed.You're screwed.

    C++/Java NOOB.

    I aint a professional at PHP, but if i can help i will.

  8. #8
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: [RESOLVED] Authentication Function HELP

    You should always have error reporting on full. If you are worried about error messages appearing in a production situation, then use an error handler function. If you know that a function call or statement can produce errors which you can safely ignore without affecting logic flow, prefix it with the @ symbol.

  9. #9
    Member
    Join Date
    Aug 2006
    Location
    Earth
    Posts
    44

    Re: [RESOLVED] Authentication Function HELP

    You also have the option of using PHP's native authentication system. It sends the authentication request to the browser as a http header.

    PHP Code:
    if(!isset($_SERVER['PHP_AUTH_USER'])) {
            
    //User Is Not Logged In
            
    header('WWW-Authenticate: Basic realm="My Realm"');
            
    header('HTTP/1.0 401 Unauthorized');
            
    //If User Hits Cancel Button
            
    print("Access Denied");
            exit;
        } else {
            
    $username $_SERVER['PHP_AUTH_USER'];
            
    $password $_SERVER['PHP_AUTH_PW'];
        };
    }; 
    Knightcon

    Mess With The Best,
    Die Like The Rest.

  10. #10
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: [RESOLVED] Authentication Function HELP

    Quote Originally Posted by PlaGuE
    True.
    But like i said.I didnt need it on at the present time.(Now i have full error reporting on.)
    The only errors i ever got were "Undefined Variables ****..." because of my $_POST variables.
    If you write your code properly (i.e: use isset() before using variables which you have not yet used), you won't get any notices. The notice serves to tell you when you have used a variable without first initialising it. So when you do receive a notice it indicates that you may have spelt a variable name incorrectly. Ignoring them is NOT good coding practice at all and is sadly yet another bad habbit that PHP programmers fall into.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  11. #11
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: [RESOLVED] Authentication Function HELP

    Quote Originally Posted by knightcon
    You also have the option of using PHP's native authentication system. It sends the authentication request to the browser as a http header.

    PHP Code:
    if(!isset($_SERVER['PHP_AUTH_USER'])) {
            
    //User Is Not Logged In
            
    header('WWW-Authenticate: Basic realm="My Realm"');
            
    header('HTTP/1.0 401 Unauthorized');
            
    //If User Hits Cancel Button
            
    print("Access Denied");
            exit;
        } else {
            
    $username $_SERVER['PHP_AUTH_USER'];
            
    $password $_SERVER['PHP_AUTH_PW'];
        };
    }; 
    It is not PHP's native system, this is the HTTP authentication system. I would not recommend using it because it relies on PHP running inside the web server process as a module.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  12. #12

    Thread Starter
    Hyperactive Member PlaGuE's Avatar
    Join Date
    Jun 2005
    Location
    in ur mind.
    Posts
    445

    Re: [RESOLVED] Authentication Function HELP

    Quote Originally Posted by penagate
    You should always have error reporting on full. If you are worried about error messages appearing in a production situation, then use an error handler function. If you know that a function call or statement can produce errors which you can safely ignore without affecting logic flow, prefix it with the @ symbol.
    I usually do that too.
    Without balance, there could only be chaos.
    Without chaos, there could be no balance.
    I live with karma. Eat with destiny. Dream of life without shackles....
    Yet. If life had no consequences, life could not exist, nor could it flourish.


    If at first you dont succeed.You're screwed.

    C++/Java NOOB.

    I aint a professional at PHP, but if i can help i will.

Posting Permissions

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



Click Here to Expand Forum to Full Width