removing user from htpasswd via php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Donkey Punch
    Confirmed User
    • Jun 2007
    • 1260

    #1

    removing user from htpasswd via php

    anyone have a snippet of code I could borrow to do this?

    or at least point me in the right direction?

    Thanks
    ICQ:407-837-607
    Hosting a Problem? Phat Servers = Answer
  • tomud
    Confirmed User
    • Jun 2002
    • 7993

    #2
    sure

    http://www.scriptsearch.com/details/964.html

    Tomud


    AFF – up to $1.50 per free join, $130 per order ! NASTYDOLLARS - 35$ PPS ! Free hosted galleries !
    ADULTDATELINK$42 PPS, 50% REV ! DATINGGOLD - 100% !!! REV, $4 per email !
    Adult Sponsors Reviews – take a look at the best adult programs !
    Epassporte Sponsors

    ICQ: 160168237

    Comment

    • fris
      Too lazy to set a custom title
      • Aug 2002
      • 55679

      #3
      30$ for a script like that? could code one quicker
      Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.

      Comment

      • Donkey Punch
        Confirmed User
        • Jun 2007
        • 1260

        #4
        that's a little over my .20 cent budget
        ICQ:407-837-607
        Hosting a Problem? Phat Servers = Answer

        Comment

        • tomud
          Confirmed User
          • Jun 2002
          • 7993

          #5
          Originally posted by Donkey Punch
          that's a little over my .20 cent budget


          Tomud


          AFF – up to $1.50 per free join, $130 per order ! NASTYDOLLARS - 35$ PPS ! Free hosted galleries !
          ADULTDATELINK$42 PPS, 50% REV ! DATINGGOLD - 100% !!! REV, $4 per email !
          Adult Sponsors Reviews – take a look at the best adult programs !
          Epassporte Sponsors

          ICQ: 160168237

          Comment

          • quantum-x
            Confirmed User
            • Feb 2002
            • 6863

            #6
            steal / use the ccbill or epoch one that everyone has.
            PrettyInCash.com - BoozedGFs.com - TeenGFs.com - JizzGFs.com- MilfUploads.com -

            Comment

            • Donkey Punch
              Confirmed User
              • Jun 2007
              • 1260

              #7
              Originally posted by quantum-x
              steal / use the ccbill or epoch one that everyone has.
              is it php or cgi ?

              and where can I get it ?

              :\
              ICQ:407-837-607
              Hosting a Problem? Phat Servers = Answer

              Comment

              • Wolfy
                Confirmed User
                • Dec 2003
                • 3574

                #8
                Originally posted by Fris
                30$ for a script like that? could code one quicker

                I bet you $60 you can't code even a hello script faster than I can swipe my VISA for $30.

                Tell me when you want to fire the gun :D

                Comment

                • Donkey Punch
                  Confirmed User
                  • Jun 2007
                  • 1260

                  #9
                  shit, got everything working..

                  sign up, recover pass and cancel (remove from db) except for the removing from htpasswd part

                  ima go crazy
                  ICQ:407-837-607
                  Hosting a Problem? Phat Servers = Answer

                  Comment

                  • Donkey Punch
                    Confirmed User
                    • Jun 2007
                    • 1260

                    #10
                    If anyone cares... I found a solution. Now to integrate it into my script

                    http://www.thewebmasters.net/php/Htpasswd.phtml

                    ;)

                    Thanks to everyone who tried to help me. I appreciate it.
                    ICQ:407-837-607
                    Hosting a Problem? Phat Servers = Answer

                    Comment

                    • budz
                      Disruptive Innovator
                      • Sep 2003
                      • 4230

                      #11
                      Thanks for the "LINK" haha ;)
                      C:\Code\
                      C:\Code\Run\

                      Comment

                      • takaya
                        Confirmed User
                        • Mar 2003
                        • 50

                        #12
                        A simple version

                        <form action=<?=$PHP_SELF?> method=post>
                        Username <input name=username><p>
                        Password <input name=password></p>
                        | Add <input type=radio name=do_what value=Add> | Modify <input type=radio name=do_what value=Modify> | Delete <input type=radio name=do_what value=Delete> |<br>
                        <input type=submit value=submit>
                        </form>
                        <?
                        // find path and filename in .htaccess
                        // change access permission of filename to to allow write
                        $htaccess_file = "path_of_file/filename";
                        $username = trim($_POST["username"]); // from yout post form
                        $password = trim($_POST["password"]); // from your post form
                        $action = $_POST["do_what"]; // from your post form
                        $user_string = $username . ":" . crypt($password) ."\n";

                        if($action == "Add") {
                        $fp=fopen($htaccess_file, "a+");
                        if ($fp) {
                        while (!feof($fp)) {
                        $htpassinfo = fgets($fp, 4096);
                        list($ht_username, $ht_password) = explode(":", $htpassinfo);
                        if(trim($username) == trim($ht_username)) {
                        echo "Username $username is already existed";
                        exit;
                        }
                        }
                        if (fwrite($fp, $user_string) === FALSE) {
                        echo "FAIL to Add";
                        fclose($fp);
                        exit;
                        }
                        fclose($fp);
                        echo "Add Successful";
                        }
                        } else {
                        $fp=fopen($htaccess_file, "r");
                        if ($fp) {
                        $i=0;
                        while (!feof($fp)) {
                        $htpassinfo = fgets($fp, 4096);
                        list($ht_username, $ht_password) = explode(":", $htpassinfo);
                        if(trim($username) == trim($ht_username)) {
                        if($action == "Delete") {
                        $htlist[$i] = "";
                        $msg = "Deleted";
                        } else if($action == "Modify") {
                        $htlist[$i] = $user_string;
                        $msg = "Modified";
                        } else {
                        $htlist[$i] = $htpassinfo;
                        }
                        } else {
                        $htlist[$i] = $htpassinfo;
                        }
                        $i++;
                        }
                        fclose($fp);
                        } else {
                        echo "fail to open file";
                        exit;
                        }
                        $fp=fopen($htaccess_file, "w");
                        if ($fp) {
                        for($i=0;$i<count($htlist);$i++) {
                        fputs($fp, $htlist[$i]);
                        }
                        echo $msg;
                        }
                        }
                        ?>

                        Comment

                        • Donkey Punch
                          Confirmed User
                          • Jun 2007
                          • 1260

                          #13
                          include("class.Htpasswd.php3");

                          $UserID = "$user";

                          $Htpasswd = new Htpasswd;
                          $Htpasswd->initialize("/home/topsecretdomainbeforewebdirectory/.htpasswd");

                          if(!($Htpasswd->EXISTS))
                          {
                          #O KNOEZ !!
                          exit;
                          }

                          if($Htpasswd->deleteUser($UserID))
                          ICQ:407-837-607
                          Hosting a Problem? Phat Servers = Answer

                          Comment

                          • J.P.
                            Confirmed User
                            • Jun 2004
                            • 689

                            #14
                            grep -Ev "^desired_username:" .htpasswd > .htpasswd.tmp;mv -f .htpasswd.tmp .htpasswd

                            you can use PHP's exec() function to execute this shell command... you will have to use full paths of course
                            Webmasters! Looking for new affiliate programs to promote?
                            Affiliate Program Search <-- Search for programs with FHGs, RSS feed, specific niche sponsors, ...

                            Comment

                            • Donkey Punch
                              Confirmed User
                              • Jun 2007
                              • 1260

                              #15
                              Originally posted by J.P.
                              grep -Ev "^desired_username:" .htpasswd > .htpasswd.tmp;mv -f .htpasswd.tmp .htpasswd

                              you can use PHP's exec() function to execute this shell command... you will have to use full paths of course
                              lol, I had the command line earlier and I gave up trying to get it to work!

                              Thanks for the post though )
                              ICQ:407-837-607
                              Hosting a Problem? Phat Servers = Answer

                              Comment

                              • takaya
                                Confirmed User
                                • Mar 2003
                                • 50

                                #16
                                ok, people asked about code.

                                The code above I posted is a working code, you need to change the path and htaccess file permission, easy way is in command line -- chmod 666 filename

                                that's it

                                Comment

                                • J.P.
                                  Confirmed User
                                  • Jun 2004
                                  • 689

                                  #17
                                  Originally posted by Donkey Punch
                                  lol, I had the command line earlier and I gave up trying to get it to work!

                                  Thanks for the post though )
                                  No problem, anytime
                                  Webmasters! Looking for new affiliate programs to promote?
                                  Affiliate Program Search <-- Search for programs with FHGs, RSS feed, specific niche sponsors, ...

                                  Comment

                                  • rowan
                                    Too lazy to set a custom title
                                    • Mar 2002
                                    • 17393

                                    #18
                                    Just be careful you don't end up with two processes writing the password file at the same time. None of the methods posted in here use locking.

                                    Comment

                                    Working...