PHP Auth

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
seeker2921
Forum Contributor
Posts: 120
Joined: Sat Mar 22, 2003 7:10 pm
Location: Wiesbaden Germany
Contact:

PHP Auth

Post by seeker2921 »

Hello,

This is my problem. Im new to PHP and im still learning. In one of my subdomains I want to have a login script that when you type in http://subdomain.TLD.com a login windows pops up.. now I got that far.. but my problem is I want each username to go to a diff folder in the subdomain. so say theres two folders folder1 & folder2 if i enter in username= f1 pw= test it should load folder1 and same if i neter in user=f2 pw=test it should take me to folder2 heres the code im using to pop up the login window. I have this code in my index.php

Code:
<?
if(($PHP_AUTH_USER == "f1") AND ($PHP_AUTH_PW == "test"))
{
print("<HTML>\n");
print("<HEAD>\n");
print("<TITLE>Welcome to Members Area</TITLE>\n");
print("</HEAD>\n");
print("<BODY>\n");
print("You have logged in successfully!<BR>\n");
}
else
{
header("WWW-Authenticate: Basic realm=\"Subdomain\"");
header("HTTP/1.0 401 Unauthorized");
print("This page is PROTECTED by HTTP Authentication.<br>\n");
print("DO NOT TRY TO ACCESS THIS SITE IF YOU ARE NOT AUTHERIZED!");
}
?>

I know that I will need aonther if for the second user but I dont know where it should go.. thanx for your help

Stephen
User avatar
Stoker
Forum Regular
Posts: 782
Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:

Post by Stoker »

!

Code: Select all

<?php

  function validate_login ($user,$pass) {
    if (empty($pass) || empty($user)) return false;
    // get logindata from somewhere or check with something else like a db (and use md5 etc instead, such as  if ($database_table_row['password'] === md5($user.$pass) ... )
    $valid = array (
       'f1' => 'test',
       'f2' => 'test'
    );

    if ($valid[$user] === $pass) return true;
    else return false;
  }

  $user = $_SERVER['PHP_AUTH_USER'];
  if( validate_login($user, $_SERVER['PHP_AUTH_PW']) )  {  ?>
     <HTML>
      <HEAD>
          <TITLE>Welcome to Members Area</TITLE>
      </HEAD>
      <BODY>
      <h3>You have successfully logged in!</h3>
      <p>Here are your options: </p>
    <?php
       $group = array(
         'f1' => 'folder1',
         'f2' => 'folder2'
       );

       include ('/path/to/file/'.$group($user));
       // or whatever it is you want this user to get or link or se etc..

 }  // end auth-content

 else {    // begin no-auth content
   header('WWW-Authenticate: Basic realm="Subdomain"');
   header("HTTP/1.0 401 Unauthorized");
   ?><p>This page is PROTECTED by HTTP Authentication.<br>
             DO NOT TRY TO ACCESS THIS SITE IF YOU ARE NOT AUTHERIZED!</p>
   <?php
 }  // end no-auth-content

?>
seeker2921
Forum Contributor
Posts: 120
Joined: Sat Mar 22, 2003 7:10 pm
Location: Wiesbaden Germany
Contact:

Post by seeker2921 »

Ok i tried it and It let me log in but right after it says "here are your options" it gives me this:

Fatal error: Call to undefined function: array() in /public_html/subdomain/index.php on line 30

Im not sure what I am supposed to but in the include path so I tried a few things.. the folders names that I want this script to go to are the just the user name with ~ in front of it so I put to full path to this..

/public_html/subdomain/~$user

and that didnt work.. so what needs to go in the include path?

Thanx for helping me..

Stephen
Post Reply