Results 1 to 8 of 8

Thread: script to check if server supports PHP-Auth?

  1. #1
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default script to check if server supports PHP-Auth?

    Just curious as sometimes contacting server admin can take forever. Is there something I can use to test if PHP_Auth is supported and working on my server?
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  2. #2
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    I believe its native as of php4.x

  3. #3
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Well, you could write a simple script to test it I suppose. That would tell you if it is in fact supported.

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  4. #4
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    okay... so I wrote this:

    PHP Code:
    <?php

    $myusername 
    "user";
    $mypassword "pass";
    $areaname "This shows on the pop up!";

    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();
    }

    ?>
    well..I didn't write it, just modified it...

    I put it on the very top (pre- opening html tag) and then browsed to that page. a passbox poped up. when I entered the correct username and password it didn't show the page, instead the passbox vanished, reappeared and both user and pass inputs were empty.

    So... why won't it work? LOL Also.. if I do get it to work, and I wantto use it server wide do I need to make the variable global, or in their own script or do I need to put the whole thing on every page?
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  5. #5
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    watch out for globals, they can get you in trouble,

    save it to a session variable

  6. #6
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    okay.. err.. how? I have about reached the end of my php knowledge and I can't find anything that seems to help through google.

    Can you help me write out something?
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  7. #7
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    Quote Originally Posted by boogyman View Post
    watch out for globals, they can get you in trouble,

    save it to a session variable
    There ARE no globals. You don't need to save it as a $_SESSION variable, because the HTTP authentication saves itself on the browser. Meaning, it won't let you logout until you close the browser.

    Blizzard, try this script:

    PHP Code:
    <?php
    $user
    ='hi';
    $pass='hi';
    if (!(isset(
    $_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW']) && $_SERVER['PHP_AUTH_USER'] == $user && $_SERVER['PHP_AUTH_PW'] == $pass))    {
    header('WWW-Authenticate: Basic realm="Secured Area!!!!"');
    header('Status: 401 Unauthorized');
    die(
    '<h1>Unauthorized Access</h1>');
    }
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Super Secret Stuff!!!</title>
    </head>

    <body>
    <h1>hi.</h1>
    </body>
    </html>
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  8. #8
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    Thanks for that, I actually wrote a better working one than I needed. Of course I need to clean it up because I know I have more in there than I need.

    But I will keep this one too, I am sure I can use it somewhere!

    Thanks!
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

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
  •