Getting Username from htaccess

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
facets
Forum Contributor
Posts: 273
Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit

Getting Username from htaccess

Post by facets »

Hi Gang,

We've been using the following code to get the username form the htaccess auth mechanism and passing it too the script. Now i've tried to install this onto php 4.3.9-3 and it's not working.

Code: Select all

include("connect.inc");
        $username = $_SERVER["REMOTE_USER"];

        // query the database, team leaders and admin can be here, no one else can
        $result1 = mysql_query("SELECT * FROM users WHERE userName='$username'");
        $result2 = mysql_query("SELECT * FROM teamLeaders WHERE userName='$username'");
        $result3 = mysql_query("SELECT * FROM salesReps WHERE userName='$username'");
        $result4 = mysql_query("SELECT * FROM executives WHERE userName='$username'");
        $result5 = mysql_query("SELECT * FROM admin WHERE userName='$username'");

	// assign the query as an array of results
        $userPass = mysql_fetch_array($result1);
        $tlPass = mysql_fetch_array($result2);
        $salesPass = mysql_fetch_array($result3);
        $execPass = mysql_fetch_array($result4);
        $adminPass = mysql_fetch_array($result5);
I was recieving a security error so I added "rvar_" in the connect.inc script and that seemed to fix that.

Code: Select all

import_request_variables("gP", "rvar_");
The next errors are :
mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /production/www/intranet/html/custcomplaints/index.php on line 45
mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /production/www/intranet/html/custcomplaints/index.php on line 46
mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /production/www/intranet/html/custcomplaints/index.php on line 47
mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /production/www/intranet/html/custcomplaints/index.php on line 48
mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /production/www/intranet/html/custcomplaints/index.php on line 49

I've tried to fix this by changing the request to the following, but still get the error.

Code: Select all

$result = mysql_query("SELECT * FROM users WHERE userName='$username'");
        $query_data = mysql_fetch_array($result);
        $userPass = $query_data["userPass"];
Can anyone shed any light on this? I've run out of things to try.

Ta, Will.
Post Reply