SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member ronnie173's Avatar
    Join Date
    May 2004
    Location
    texas
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    $PHP_AUTH_USER help

    Can anyone help me configure this user authorization for php.4.0 because it doesn't work on the server that I am running it on. I think that I am suppose to add $SERVER to it but I do not know how to write the correct syntax for it. Here is a sample of my script. This configuration does not work.

    <?
    require("config.php");
    // admin interface
    $dbh = mysql_connect ($conf[dbhost], $conf[dbuser], $conf[dbpass]) or die (mysql_error());
    mysql_select_db ($conf[dbname]);
    if ((!isset($PHP_AUTH_USER)) || (!isset($PHP_AUTH_PW)) || ($PHP_AUTH_USER != $conf[adminuser]) || ($PHP_AUTH_PW != $conf[adminpass])) {
    header('WWW-Authenticate: Basic realm="Private Area"');
    header("HTTP/1.1 401 Unauthorized");
    print "This page requires authorisation.";
    exit();
    } else {
    if(!$mode) {

    $sql = "SELECT * FROM `people`";
    $pr = mysql_query($sql);
    $ctne = '';
    while ($row=mysql_fetch_array($pr)) {
    $ctne .= "<b>".$row[name]."</b> - ".$row[email]." [".$row[amount]."] <a href=\"admin.php?mode=delete&id=".$row[id]."\">Remove</a><br>\n";
    }

    If antone can help me with this Thanks in advance
    ronnie173

  2. #2
    SitePoint Enthusiast EspenA's Avatar
    Join Date
    May 2004
    Location
    Norway, Oslo
    Posts
    85
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi ronnie173,

    Try this code:

    PHP Code:
    <?php

      
    require("config.php");

      
    // admin interface
      
    $dbh mysql_connect ($conf[dbhost], $conf[dbuser], $conf[dbpass]) or die (mysql_error());
      
    mysql_select_db ($conf[dbname]);

      if ((!isset(
    $_SERVER['PHP_AUTH_USER'])) || (!isset($_SERVER['PHP_AUTH_PW'])) || 
      (
    $_SERVER['PHP_AUTH_USER'] != $conf[adminuser]) || ($_SERVER['PHP_AUTH_PW'] != $conf[adminpass])) {
        
    header('WWW-Authenticate: Basic realm="Private Area"');
        
    header("HTTP/1.1 401 Unauthorized");
        print 
    "This page requires authorisation.";
        exit();
      } else {
        if(!
    $mode) {
          
    $sql "SELECT * FROM `people`";
          
    $pr mysql_query($sql);
          
    $ctne '';

          while (
    $row mysql_fetch_array($pr)) {
            
    $ctne .= "<b>".$row[name]."</b> - ".$row[email]." [".$row[amount]."] 
            <a href=\"admin.php?mode=delete&id="
    .$row[id]."\">Remove</a><br>\n";
          }
    Note: Is $mode defined in the uri? If it is, use $_GET['mode'] instead.


Bookmarks

Posting Permissions

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