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 11 of 11

Thread: .htaccess login

  1. #1
    Senior Coder chilipie's Avatar
    Join Date
    Jul 2004
    Location
    Shrewsbury, UK Age: 16
    Posts
    1,117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation .htaccess login

    2 Questions:

    1. Can you logout from a (.htaccess) session by clicking on a link, and if yes how?

    2. Is there a way of using an HTML form to login to a .htaccess protected directory?

    Thanks in advance .
    Last edited by chilipie; 10-27-2004 at 01:26 PM.

  • #2
    Regular Coder
    Join Date
    May 2004
    Posts
    121
    Thanks
    0
    Thanked 0 Times in 0 Posts
    1. No. Not really. Maybe.
    http://www.ssi-developer.net/htacces...s_logout.shtml

    2. No. If you want to use a form you need PHP or Perl.

  • #3
    Senior Coder chilipie's Avatar
    Join Date
    Jul 2004
    Location
    Shrewsbury, UK Age: 16
    Posts
    1,117
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok thanks, that articles interesting. I might have a go at that...

    Is using PHP or Perl more secure than .htaccess?

  • #4
    Senior Coder gsnedders's Avatar
    Join Date
    Jan 2004
    Posts
    2,340
    Thanks
    1
    Thanked 7 Times in 7 Posts
    Yes, you can use a form, I'd recommend you use a PHP or other server side script for this...

    PHP example:
    login.html
    Code:
    <form action="login.php" method="post">
    Username: <input type="text" name="user" /><br />
    Password: <input type="password" name="pass" />
    </form>
    login.php
    PHP Code:
    <?PHP
    $user 
    $_POST['user'];
    $pass $_POST['pass'];
    If (
    $user == '') || ($pass == '') {
    echo 
    'No Username or Password';
    } else {
    header ("Location: http://$user:$pass@example.com/htaccess/");
    }
    ?>
    JavaScript
    If you don't have PHP, there's always JavaScript, but remember it can be disabled....

    http://javascript.internet.com/navig...ess-login.html
    Last edited by gsnedders; 10-28-2004 at 10:14 PM.

  • #5
    Senior Coder chilipie's Avatar
    Join Date
    Jul 2004
    Location
    Shrewsbury, UK Age: 16
    Posts
    1,117
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hmm....

    I copied the PHP code and changed the domain etc. and got the following error.

    Parse error: parse error, unexpected T_BOOLEAN_OR in /home/redblizz/public_html/haze8/login.php on line 4
    (Just in case I did change something accidently, here's my code.)

    PHP Code:
    <?PHP
    $user 
    $_POST['user'];
    $pass $_POST['pass'];
    If (
    $user == '') || ($pass == '') {
    echo 
    'No Username or Password';
    } else {
    header ("Location: http://$user:$pass@redblizzard.astahost.com/haze8/private/");
    }
    ?>

  • #6
    Regular Coder
    Join Date
    Jun 2004
    Posts
    112
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I wrote this in the box here, so it may have an error.

    I think this is what you are looking for? Perhaps you are still trying to incorporate htaccess though?

    PHP Code:
    <?PHP
    $users 
    = array(
    'username' => 'password',
    );

    if(empty(
    $_POST['user']) || empty($_POST['pass'])
    {
    echo 
    'No Username or Password';
    }else
    {
    if(isset(
    $users[$_POST['user']]))
    {
    if(
    strtolower($users[$_POST['user']]) == strtolower($_POST['pass'])))
    {
    header ('Location: http://place');
    }else
    {
    echo 
    'Invalid Password';
    }
    }else
    {
    echo 
    'Invalid Username';
    }
    }
    ?>

  • #7
    Senior Coder chilipie's Avatar
    Join Date
    Jul 2004
    Location
    Shrewsbury, UK Age: 16
    Posts
    1,117
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by bnovc
    Perhaps you are still trying to incorporate htaccess though?
    Yep. What I am trying to do is use a PHP script to login to an area (directory/folder, whatever) protected by .htaccess.

  • #8
    Senior Coder gsnedders's Avatar
    Join Date
    Jan 2004
    Posts
    2,340
    Thanks
    1
    Thanked 7 Times in 7 Posts
    Quote Originally Posted by chilipie
    Hmm....

    I copied the PHP code and changed the domain etc. and got the following error.



    (Just in case I did change something accidently, here's my code.)

    PHP Code:
    <?PHP
    $user 
    $_POST['user'];
    $pass $_POST['pass'];
    If (
    $user == '') || ($pass == '') {
    echo 
    'No Username or Password';
    } else {
    header ("Location: http://$user:$pass@redblizzard.astahost.com/haze8/private/");
    }
    ?>
    My fault...

    PHP Code:
    <?PHP
    $user 
    $_POST['user'];
    $pass $_POST['pass'];
    If (
    $user == '' || $pass == '') {
    echo 
    'No Username or Password';
    } else {
    header ("Location: http://$user:$pass@redblizzard.astahost.com/haze8/private/");
    }
    ?>
    That should work...

  • #9
    Senior Coder chilipie's Avatar
    Join Date
    Jul 2004
    Location
    Shrewsbury, UK Age: 16
    Posts
    1,117
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks . The only bad thing is that the user/password is shown in the address bar. Is it possible to stop that?

  • #10
    Senior Coder gsnedders's Avatar
    Join Date
    Jan 2004
    Posts
    2,340
    Thanks
    1
    Thanked 7 Times in 7 Posts
    Quote Originally Posted by chilipie
    Thanks . The only bad thing is that the user/password is shown in the address bar. Is it possible to stop that?
    Nope...

  • #11
    Senior Coder JamieR's Avatar
    Join Date
    Oct 2004
    Location
    United Kingdom
    Posts
    3,161
    Thanks
    0
    Thanked 5 Times in 5 Posts
    there *should* be a way to supress the outputted URL from the script that masks the username and password in the URL string.


  •  

    Posting Permissions

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