Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Sep 2007
    Posts
    264
    Thanks
    19
    Thanked 0 Times in 0 Posts

    PHP Password Script

    I have a password script that I would like to embed php in. Ex:
    Code:
    <?php
    
    $myusername = "usar";
    $mypassword = "passward";
    $areaname = "Area";
    
    if ($_SERVER["PHP_AUTH_USER"] == "" || $_SERVER["PHP_AUTH_PW"] == "" || $_SERVER["PHP_AUTH_USER"] != $myusername || $_SERVER["PHP_AUTH_PW"] != $mypassword) {
        header("HTTP/1.0 401 Unauthorized");
        header("WWW-Authenticate: Basic realm=\"$areaname\"");
        echo "<h1>Authorization Required</h1>";
        die();
    }
    
    ?>
    I'm wondering two things. First is only if option 2 is not available, which is... If the password is incorrect how can I redirect? I found:
    Code:
    header('Location: http://www.example.com/');
    But it's not working.


    Option 2. I was hoping to display a custom error in php, but anything after the code above is password protected... So is it possible to get PHP inside there to use it as a custom message or would I have to redirect to a php page for this?

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    See this page for http authentication: http://ca.php.net/manual/en/features.http-auth.php

    It should be noted that this will only run on builds for Apache module php, not on IIS or CGI based versions.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •