Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

$SERVER'PHP_AUTH_USER

Posted on 2009-12-17
3
Medium Priority
?
442 Views
Last Modified: 2013-12-12
Hello there, I believe this is a very easy fix for any experianced php and mysql guy. basiclly all i need is something like this...

  if (!isset($_SERVER['PHP_AUTH_USER'])) {
        header("WWW-Authenticate: Basic realm=\"Calendar\"");
        header("HTTP/1.0 401 Unauthorized");
        print "Sorry - you need valid credentials to be granted access!\n";
        exit;
    } else {
        if (($_SERVER['PHP_AUTH_USER'] == '') && ($_SERVER['PHP_AUTH_PW'] == '')) {
            print "Welcome to the staff area!";
       } else {
        if (($_SERVER['PHP_AUTH_USER'] == '') && ($_SERVER['PHP_AUTH_PW'] == '')) {
            print "Welcome to the students area!";
        } else {
            header("WWW-Authenticate: Basic realm=\"Private Area\"");
            header("HTTP/1.0 401 Unauthorized");
            print "Sorry - you need valid credentials to be granted access!\n";
            exit;
        }
    }

But what i need it to be able to do is capture the first letter of every persons log in name.. and direct them to the page depending on what their first Letter of their login username is for example for the students.. it will be all letters apart from U will be student logins..

then for staff page only the U letters at the start of the login will be used to login to the staff page..

they will then be re-directed to the relevant page...

i believe the way to do is Substrings?? but i have no idea on how to do this and everything ive tried has not worked.

I hope someone knows the answer to this, thank you for your help in advanced its greatly appricated.
0
Comment
Question by:NeoAshura
3 Comments
 
LVL 51

Accepted Solution

by:
Steve Bink earned 2000 total points
ID: 26077348
What you need is the substr() function:

http://us3.php.net/manual/en/function.substr.php


<?
$username=((array_key_exists('PHP_AUTH_USER',$_SERVER))?$_SERVER['PHP_AUTH_USER']:'');
$firstletter=substr($username,0,1);    // <---------------------------- the mojo
switch ($firstletter) {
  case 'U':
    // this is a staff login
    break;
  case 'Z':
    // this is some other future expansion
    break;
  default:
    // this is everybody else
    break;
}
?>

Open in new window

0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 26079134
Also

$firstletter=$username{0};
$firstletter=$username[0];

are both currently supported, but {} is deprecated as of 5.3.0 and [] is the recommended approach.
0
 
LVL 6

Author Closing Comment

by:NeoAshura
ID: 31667260
exellent
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This holiday season, we’re giving away the gift of knowledge—tech knowledge, that is. Keep reading to see what hacks, tips, and trends we have wrapped and waiting for you under the tree.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

572 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question