[PHP] Help Pl0x :S

Discussion in 'Web Programming' started by demonavenger, Aug 11, 2008.

[PHP] Help Pl0x :S
  1. Unread #1 - Aug 11, 2008 at 8:35 PM
  2. demonavenger
    Joined:
    Feb 25, 2007
    Posts:
    536
    Referrals:
    0
    Sythe Gold:
    0

    demonavenger Forum Addict
    $5 USD Donor

    [PHP] Help Pl0x :S

    Hey guys, i am having a bit of trouble with php and only just started learning, i am wanting a basic user auth to access another php file, but i dont want it to connect through a MySQL data base or w/e... can anyone help me :D

    ::EDIT::
    I have read tutorials and all, but i can't seem to get it right...
    The website I was looking at was: http://au2.php.net/features.http-auth

    Please someone help >_<
     
  3. Unread #2 - Aug 12, 2008 at 10:40 AM
  4. Furbster4
    Joined:
    Jun 16, 2008
    Posts:
    24
    Referrals:
    0
    Sythe Gold:
    0

    Furbster4 Newcomer

    [PHP] Help Pl0x :S

    well, have a form, two fields, one called username and other called password, then have it go to login.php

    in login.php have
    Code:
    <?php
    
    $username = $_POST['username'];
    $password = $_POST['password'];
    
    $users = "filename.txt";
    
    $contents = fread($users, filesize($users));
    if (preg_match("/".$username."-".$password."/"im, $contents)) {
    echo "Now Logged In!";
    }else {
    die("Wrong details.");
    }
    ?>
    
    in the second file have it set up as
    and so on and forth.

    This is untested but should work ;)
     
  5. Unread #3 - Aug 12, 2008 at 7:08 PM
  6. demonavenger
    Joined:
    Feb 25, 2007
    Posts:
    536
    Referrals:
    0
    Sythe Gold:
    0

    demonavenger Forum Addict
    $5 USD Donor

    [PHP] Help Pl0x :S

    Thanks that is a start, but isn't the type of auth i wanted... what i wanted was this:
    [​IMG]
    it is supposed to pop up asking for details... >_<
     
  7. Unread #4 - Aug 13, 2008 at 12:12 AM
  8. Jazz00006
    Joined:
    Aug 26, 2005
    Posts:
    807
    Referrals:
    0
    Sythe Gold:
    0

    Jazz00006 Apprentice
    Visual Basic Programmers

    [PHP] Help Pl0x :S

    that's most likely a htpasswd protection scheme (Google will help you more at this point)
    You'll need two files, .htaccess and .htpasswd, and if your server is running IIS it wont work.
     
  9. Unread #5 - Aug 14, 2008 at 8:32 PM
  10. demonavenger
    Joined:
    Feb 25, 2007
    Posts:
    536
    Referrals:
    0
    Sythe Gold:
    0

    demonavenger Forum Addict
    $5 USD Donor

    [PHP] Help Pl0x :S

    :huh: hmm... i am sure i have seen it down on php as well... eg:
    Code:
    if (!isset($_SERVER['PHP_AUTH_USER'])) {
    
        header('WWW-Authenticate: Basic realm="My Realm"');
        header('HTTP/1.0 401 Unauthorized');
    } else {
    
    and so on, etc... but i dont fully understand it, i have tried google and found a site containing stuff like this, but as i said i dont fully understand how it works >_<
     
  11. Unread #6 - Aug 14, 2008 at 9:16 PM
  12. Deacon Frost
    Joined:
    Jan 30, 2007
    Posts:
    2,905
    Referrals:
    3
    Sythe Gold:
    57

    Deacon Frost Grand Master
    Banned

    [PHP] Help Pl0x :S

    Here's a nice free script that does that. It's just a password, not a user.

    PHP:
    <?php
    /*************************************************
     * Max's Site Protector
     *
     * Version: 1.0
     * Date: 2007-11-27
     *
     ****************************************************/
    class maxProtector{
        var 
    $password 'aisudfha';
        
        function 
    showLoginForm(){
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
       <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
       <title>Max's File Uploader</title>
       <link href="style/style.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
           <div id="container">
                <div id="header"><div id="header_left"></div>
                <div id="header_main">Max's Site Protector</div><div id="header_right"></div></div>
                <div id="content">
                    <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
                         <center>
                             <label>Password:
                                 <input name="passwd" type="password" size="20" />
                             </label><br/>
                             <label>
                                 <input type="submit" name="submitBtn" class="sbtn" value="Login" />
                             </label>
                         </center>
                     </form>
                 </div>
                 <div id="footer"><a href="http://www.phpf1.com" target="_blank">Powered by PHP F1</a></div>
             </div>
    </body>         
    <?php
        
    }

        function 
    login(){
            
    $loggedin = isset($_SESSION['loggedin']) ? $_SESSION['loggedin'] : false;
            if ( (!isset(
    $_POST['submitBtn'])) && (!($loggedin))){
                
    $_SESSION['loggedin'] = false;
                   
    $this->showLoginForm();
                   exit();
            } else if (isset(
    $_POST['submitBtn'])) {
                   
    $pass = isset($_POST['passwd']) ? $_POST['passwd'] : '';
          
                   if (
    $pass != $this->password) {
                       
    $_SESSION['loggedin'] = false;
                       
    $this->showLoginForm();
                       exit();     
                   } else {
                       
    $_SESSION['loggedin'] = true;
                   }
            }

        }
    }

    // Auto create
    session_start();
    $protector = new maxProtector();
    $protector->login();
    ?>
    And then in all the files you want it to protect...

    PHP:
    <?php require_once("maxProtector.class.php"); ?>



    However, if you want to have a user and password collection on text files, that's possible, but it'd take some alteration, and you'd have to have a series of strings/ifs/ and possibilities... probably ending in a bit of hacking, unsafeness.


    This script works well, i've had no problems with it:

    http://downstage.tv/game/


    Just remember, if you use it, that you have to CLICK THE LOGIN BUTTON. You can't just press enter... it doesn't work.


    Enjoy, any alterations needed will cost :p ;).
     
  13. Unread #7 - Aug 14, 2008 at 9:17 PM
  14. cp
    Joined:
    Jan 30, 2007
    Posts:
    3,278
    Referrals:
    6
    Sythe Gold:
    0

    cp an cat
    Banned

    [PHP] Help Pl0x :S

    Code:
    <?PHP if (!isset($_SERVER['PHP_AUTH_USER']) && !isset ($_SERVER['PHP_AUTH_PW']))
    {
    header('WWW-Authenticate: Basic realm="my Realm"');
    header('HTTP/1.0 401 Unauthorized');
    echo '<b>Authorization Required - Access Denied!</b>';
    // now unset user/name entered to retry
    unset($_SERVER['PHP_AUTH_USER']);
    unset($_SERVER['PHP_AUTH_PW']);
    exit;
    }
    else
    {
    // user is now auth
    echo 'Welcome ' . $_SERVER['PHP_AUTH_USER'];
    } ?>
    (http://www.phpbuilder.com/board/archive/index.php/t-10257980.html)

    I've tested it, and it works perfectly as if you used an .htaccess file.
     
  15. Unread #8 - Aug 14, 2008 at 10:24 PM
  16. demonavenger
    Joined:
    Feb 25, 2007
    Posts:
    536
    Referrals:
    0
    Sythe Gold:
    0

    demonavenger Forum Addict
    $5 USD Donor

    [PHP] Help Pl0x :S

    Um... as i said i dont understand php very well.. but where do i put the password (l0l >_<)
     
  17. Unread #9 - Aug 14, 2008 at 10:34 PM
  18. cp
    Joined:
    Jan 30, 2007
    Posts:
    3,278
    Referrals:
    6
    Sythe Gold:
    0

    cp an cat
    Banned

    [PHP] Help Pl0x :S

    You have to do the password checking yourself.
    Code:
    <?PHP if (!isset($_SERVER['PHP_AUTH_USER']) && !isset ($_SERVER['PHP_AUTH_PW']))
    {
    header('WWW-Authenticate: Basic realm="Enter User Data!"');
    header('HTTP/1.0 401 Unauthorized');
    echo '<b>Authorization Required - Access Denied!</b>';
    // now unset user/name entered to retry
    unset($_SERVER['PHP_AUTH_USER']);
    unset($_SERVER['PHP_AUTH_PW']);
    exit;
    }
    else
    {
    if($_SERVER['PHP_AUTH_USER']=="USERNAME" && $_SERVER['PHP_AUTH_PW']=="PASSWORD") {
    echo "You are logged in!";
    }
    else {
    echo "Wrong password information!";
    }
    } ?>
     
  19. Unread #10 - Aug 17, 2008 at 7:14 PM
  20. demonavenger
    Joined:
    Feb 25, 2007
    Posts:
    536
    Referrals:
    0
    Sythe Gold:
    0

    demonavenger Forum Addict
    $5 USD Donor

    [PHP] Help Pl0x :S

    Grr... Still doesnt work... its prob the host i am using >_<
     
  21. Unread #11 - Aug 19, 2008 at 3:10 PM
  22. Nullware
    Joined:
    Jan 30, 2007
    Posts:
    1,761
    Referrals:
    4
    Sythe Gold:
    0

    Nullware Guru

    [PHP] Help Pl0x :S

    What doesn't work exactly..?
     
  23. Unread #12 - Aug 19, 2008 at 3:35 PM
  24. cp
    Joined:
    Jan 30, 2007
    Posts:
    3,278
    Referrals:
    6
    Sythe Gold:
    0

    cp an cat
    Banned

    [PHP] Help Pl0x :S

    Do you get any error messages...? None of the functions are generally disabled on any hosts...
     
< Basics of HTML | Tutorials >

Users viewing this thread
1 guest


 
 
Adblock breaks this site