SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Authentication

  1. #1
    [Call me Bram] iBram007's Avatar
    Join Date
    Feb 2001
    Location
    Belgium
    Posts
    339
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello,

    I wrote a simple authentication script, it works, but when I save it in a function in my config.php (which is included in every page in my admin dir), the script never recognize the password...
    This is my script (user: user, pwd: password):
    PHP Code:
    function loginf(){
    if(!isset(
    $PHP_AUTH_USER)) {
        
    Header("WWW-Authenticate: Basic realm=\"AdminDir\"");
        
    Header("HTTP/1.0 401 Unauthorized");
        echo 
    "You're not allowed to access this directory!";
        exit;
    }
    else{
        if((
    $PHP_AUTH_USER == 'user') && ($PHP_AUTH_PW == 'password')){
            print(
    "Logged in!<br>");
            exit;
        }
        else{
            print(
    "You're not allowed to access this directory!");
            exit;
        }
    }

    Is their something wrong with this

  2. #2
    Grumpy Mole Man Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,067
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think this is a problem with global variables. Add the following line to the very beginning of your function:
    PHP Code:
    function loginf(){
        global 
    $PHP_AUTH_USER$PHP_AUTH_PW

  3. #3
    [Call me Bram] iBram007's Avatar
    Join Date
    Feb 2001
    Location
    Belgium
    Posts
    339
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yep, that works!

    Can you explain me what it does "global"?

  4. #4
    SitePoint Enthusiast djrs's Avatar
    Join Date
    Feb 2001
    Location
    Canada
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Globally accessible variables. basically it means the variable can be used by every loop, etc... in the script.
    http://www.hostinquiry.com
    Look up your host today!
    ----------------------------
    ~Dylan Schiedel

  5. #5
    [Call me Bram] iBram007's Avatar
    Join Date
    Feb 2001
    Location
    Belgium
    Posts
    339
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    But in that function, what's the meaning of "global"?
    example
    when I've got 2 variables outside the function, normally you import them in the function as follow:
    PHP Code:
     function test(var1,var2){ blablabla 
    But is that the same as this:
    PHP Code:
    // $var1 and $var2 are set before the function
    function test(){
    global 
    $var1$var2;



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
  •