Posted on 2009-12-17
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";
    } 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";

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.
Question by:NeoAshura
    LVL 50

    Accepted Solution

    What you need is the substr() function:

    $firstletter=substr($username,0,1);    // <---------------------------- the mojo
    switch ($firstletter) {
      case 'U':
        // this is a staff login
      case 'Z':
        // this is some other future expansion
        // this is everybody else

    Open in new window

    LVL 40

    Expert Comment



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

    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
    Part of the Global Positioning System A geocode ( is the major subset of a GPS coordinate (, the other parts being the altitude and t…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now