#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    60
    Rep Power
    15
    I am attempting to make a login page which will then allow someone to add/edit/delete records from a table in MySQL. I was using .htaccess and it worked fine, but I want to switch to PHP now. I saw a tutorial at webmonkey and I edited it to come out with this:
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    <html>
    <body>
    <?php
    if (!isset($PHP_AUTH_USER)) {
    header('WWW-Authenticate: Basic realm="Private"');
    header('HTTP/1.0 401 Unauthorized');
    echo 'Authorization Required.';
    exit;
    } else if (isset($PHP_AUTH_USER)) {
    $db = mysql_connect("localhost", "*****", "****");
    mysql_select_db("*****",$db);
    $result = mysql_query("SELECT * FROM cg_admin WHERE login = $PHP_AUTH_USER");
    if ($row = mysql_fetch_array($result)) {
    $salt = substr($row["pass"], 0, 2);
    $enc_pw = crypt($PHP_AUTH_PW, $salt);
    if ($row["pass"] == "$enc_pw") {
    $auth = 1;
    break;
    } else {
    $auth = 0;
    }
    } else {
    $auth = 0;
    }
    // check value of $auth
    if ($auth == "1") {
    echo "You're authorized!";
    } else {
    header('WWW-Authenticate: Basic realm="Private"');
    header('HTTP/1.0 401 Unauthorized');
    echo 'Authorization Required.';
    exit;
    }
    }
    ?>
    </body>
    </html>
    [/code]
    Now this DOES tell me I need to authenticate, but it never asks me to log in. How would I do that?

    Thanks!
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    13
    Rep Power
    0
    I believe you need to put the auth part at the very beginning (before the <html> tab). Then include a new login form php when login is needed.

    Hope this is helpful.

    -------- http://www.stories-online.net/

    WARNING: adult site.

Similar Threads

  1. Mysql problem.
    By Nik in forum MySQL Help
    Replies: 54
    Last Post: December 21st, 2006, 07:02 PM
  2. Upgrade from access to mysql
    By karib1 in forum ASP Programming
    Replies: 7
    Last Post: December 16th, 2003, 01:35 PM
  3. Upgrade from access to mysql
    By karib1 in forum MySQL Help
    Replies: 1
    Last Post: December 16th, 2003, 01:27 AM
  4. problem: asp files, from access to mysql
    By karib1 in forum MySQL Help
    Replies: 1
    Last Post: November 26th, 2003, 04:16 AM

IMN logo majestic logo threadwatch logo seochat tools logo