.htaccess Tutorial

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    .htaccess Tutorial

    Part 1 - Introduction
    Part 2 - .htaccess Commands
    Part 3 - Password Protection

    Part 1

    Introduction

    In this tutorial you will find out about the .htaccess file and the power it has to improve your website. Although .htaccess is only a file, it can change settings on the servers and allow you to do many different things, the most popular being able to have your own custom 404 error pages. .htaccess isn't difficult to use and is really just made up of a few simple instructions in a text file.

    Will My Host Support It?

    This is probably the hardest question to give a simple answer to. Many hosts support .htaccess but don't actually publicise it and many other hosts have the capability but do not allow their users to have a .htaccess file. As a general rule, if your server runs Unix or Linux, or any version of the Apache web server it will support .htaccess, although your host may not allow you to use it.

    A good sign of whether your host allows .htaccess files is if they support password protection of folders. To do this they will need to offer .htaccess (although in a few cases they will offer password protection but not let you use .htaccess). The best thing to do if you are unsure is to either upload your own .htaccess file and see if it works or e-mail your web host and ask them.

    What Can I Do?

    You may be wondering what .htaccess can do, or you may have read about some of its uses but don't realise how many things you can actually do with it.

    There is a huge range of things .htaccess can do including: password protecting folders, redirecting users automatically, custom error pages, changing your file extensions, banning users with certian IP addresses, only allowing users with certain IP addresses, stopping directory listings and using a different file as the index file.

    Creating A .htaccess File

    Creating a .htaccess file may cause you a few problems. Writing the file is easy, you just need enter the appropriate code into a text editor (like notepad). You may run into problems with saving the file. Because .htaccess is a strange file name (the file actually has no name but a 8 letter file extension) it may not be accepted on certain systems (e.g. Windows 3.1). With most operating systems, though, all you need to do is to save the file by entering the name as:

    ".htaccess"

    (including the quotes). If this doesn't work, you will need to name it something else (e.g. htaccess.txt) and then upload it to the server. Once you have uploaded the file you can then rename it using an FTP program.

    Warning

    Before beginning using .htaccess, I should give you one warning. Although using .htaccess on your server is extremely unlikely to cause you any problems (if something is wrong it simply won't work), you should be wary if you are using the Microsoft FrontPage Extensions. The FrontPage extensions use the .htaccess file so you should not really edit it to add your own information. If you do want to (this is not recommended, but possible) you should download the .htaccess file from your server first (if it exists) and then add your code to the beginning.

    Custom Error Pages

    The first use of the .htaccess file which I will cover is custom error pages. These will allow you to have your own, personal error pages (for example when a file is not found) instead of using your host's error pages or having no page. This will make your site seem much more professional in the unlikely event of an error. It will also allow you to create scripts to notify you if there is an error (for example I use a PHP script on Free Webmaster Help to automatically e-mail me when a page is not found).

    You can use custom error pages for any error as long as you know its number (like 404 for page not found) by adding the following to your .htaccess file:

    ErrorDocument errornumber /file.html

    For example if I had the file notfound.html in the root direct
    ory of my site and I wanted to use it for a 404 error I would use:

    ErrorDocument 404 /notfound.html

    If the file is not in the root directory of your site, you just need to put the path to it:

    ErrorDocument 500 /errorpages/500.html

    These are some of the most common errors:

    401 - Authorization Required
    400 - Bad request
    403 - Forbidden
    500 - Internal Server Error
    404 - Wrong page

    Then, all you need to do is to create a file to display when the error happens and upload it and the .htaccess file.

    Part 2

    Introduction

    In the last part I introduced you to .htaccess and some of its useful features. In this part I will show you how to use the .htaccess file to implement some of these.

    Stop A Directory Index From Being Shown

    Sometimes, for one reason or another, you will have no index file in your directory. This will, of course, mean that if someone types the directory name into their browser, a full listing of all the files in that directory will be shown. This could be a security risk for your site.

    To prevent against this (without creating lots of new 'index' files, you can enter a command into your .htaccess file to stop the directory list from being shown:

    Options -Indexes

    Deny/Allow Certian IP Addresses

    In some situations, you may want to only allow people with specific IP addresses to access your site (for example, only allowing people using a particular ISP to get into a certian directory) or you may want to ban certian IP addresses (for example, keeping disruptive memembers out of your message boards). Of course, this will only work if you know the IP addresses you want to ban and, as most people on the internet now have a dynamic IP address, so this is not always the best way to limit usage.

    You can block an IP address by using:

    deny from 000.000.000.000

    where 000.000.000.000 is the IP address. If you only specify 1 or 2 of the groups of numbers, you will block a whole range.

    You can allow an IP address by using:

    allow from 000.000.000.000

    where 000.000.000.000 is the IP address. If you only specify 1 or 2 of the groups of numbers, you will allow a whole range.

    If you want to deny everyone from accessing a directory, you can use:

    deny from all

    but this will still allow scripts to use the files in the directory.

    Alternative Index Files

    You may not always want to use index.htm or index.html as your index file for a directory, for example if you are using PHP files in your site, you may want index.php to be the index file for a directory. You are not limited to 'index' files though. Using .htaccess you can set foofoo.blah to be your index file if you want to!

    Alternate index files are entered in a list. The server will work from left to right, checking to see if each file exists, if none of them exisit it will display a directory listing (unless, of course, you have turned this off).

    DirectoryIndex index.php index.php3 messagebrd.pl index.html index.htm

    Redirection

    One of the most useful functions of the .htaccess file is to redirect requests to different files, either on the same server, or on a completely different web site. It can be extremely useful if you change the name of one of your files but allow users to still find it. Another use (which I find very useful) is to redirect to a longer URL, for example in my newsletters I can use a very short URL for my affiliate links. The following can be done to redirect a specific file:

    Redirect /location/from/root/file.ext http://www.othersite.com/new/file/location.xyz

    In this above example, a file in the root directory called oldfile.html would be entered as:

    /oldfile.html

    and a file in the old subdirectory would be entered as:

    /old/oldfile.html

    You can also redirect whole directoires of your site using the .htaccess file, for example if you had a directory called olddirectory on your site and you had set up the same files on a new site at: http://www.newsite.com/newdirectory/ you could redirect all the files in that directory without having to specify each one:

    Redirect /olddirectory http://www.newsite.com/newdirectory

    Then, any request to your site below /olddirectory will bee redirected to the new site, with the
    extra information in the URL added on, for example if someone typed in:

    http://www.youroldsite.com/olddirecotry/ol...mages/image.gif

    They would be redirected to:

    http://www.newsite.com/newdirectory/oldfil...mages/image.gif

    This can prove to be extremely powerful if used correctly.

    Part 3


    Introduction

    Although there are many uses of the .htaccess file, by far the most popular, and probably most useful, is being able to relaibly password protect directories on websites. Although JavaScript etc. can also be used to do this, only .htaccess has total security (as someone must know the password to get into the directory, there are no 'back doors')

    The .htaccess File

    Adding password protection to a directory using .htaccess takes two stages. The first part is to add the appropriate lines to your .htaccess file in the directory you would like to protect. Everything below this directory will be password protected:

    AuthName "Section Name"
    AuthType Basic
    AuthUserFile /full/path/to/.htpasswd
    Require valid-user

    There are a few parts of this which you will need to change for your site. You should replace "Section Name" with the name of the part of the site you are protecting e.g. "Members Area".

    The /full/parth/to/.htpasswd should be changed to reflect the full server path to the .htpasswd file (more on this later). If you do not know what the full path to your webspace is, contact your system administrator for details.

    The .htpasswd File

    Password protecting a directory takes a little more work than any of the other .htaccess functions because you must also create a file to contain the usernames and passwords which are allowed to access the site. These should be placed in a file which (by default) should be called .htpasswd. Like the .htaccess file, this is a file with no name and an 8 letter extension. This can be placed anywhere within you website (as the passwords are encrypted) but it is advisable to store it outside the web root so that it is impossible to access it from the web.

    Entering Usernames And Passwords

    Once you have created your .htpasswd file (you can do this in a standard text editor) you must enter the usernames and passwords to access the site. They should be entered as follows:

    username:password

    where the password is the encrypted format of the password. To encrypt the password you will either need to use one of the premade scripts available on the web or write your own. There is a good username/password service at the KxS site which will allow you to enter the user name and password and will output it in the correct format.

    For multiple users, just add extra lines to your .htpasswd file in the same format as the first. There are even scripts available for free which will manage the .htpasswd file and will allow automatic adding/removing of users etc.

    Accessing The Site

    When you try to access a site which has been protected by .htaccess your browser will pop up a standard username/password dialog box. If you don't like this, there are certain scripts available which allow you to embed a username/password box in a website to do the authentication. You can also send the username and password (unencrypted) in the URL as follows:

    http://username:password@www.website.com/directory/

    Summary

    .htaccess is one of the most useful files a webmaster can use. There are a wide variety of different uses for it which can save time and increase security on your website.

    Here is a small example of .htaccess for wap:

    php_value register_globals 1
    DirectoryIndex index.php index.wml

    ErrorDocument 404 http://2wap.net
    addtype audio/x-mpegurl m3u
    addtype audio/mpegurl m3u
    addtype text/vnd.wap.wml wml
    addtype application/vnd.wap.wmlc wmlc
    addtype text/vnd.wap.wmlscript wmls
    addtype application/vnd.wap.wmlscriptc wmlsc
    addtype image/vnd.wap.wbmp wbmp
    addType application/java-archive jar
    addType application/x-java-archive jar
    addType text/vnd.sun.j2me.app-descriptor;charset=UTF-8 jad
    addType application/vnd.symbian.install sis
    addType audio/3gpp 3gp
    addType video/3gpp 3gp
    addType audio/x-wav wav
    addType audio/amr amr
    addType audio/amr-wb awb
    addType audio/mpeg mp3
    addType audio/x-midi mid
    addType audio/midi mid
    addType audio/midi midi
    addType application/x-smaf mmf
    addType application/vnd.smaf mmf
    addType application/vnd.mophun.application mpn
    addType application/vnd.mophun.application mpc
    addType application/vnd.eri.thm thm
    addType application/vnd.nok-s40theme nth
    Advertise your mobile site for FREE with AdTwirl


    #2
    so gumslone can u give more info and more stuffs it can use to do?

    Comment


      #3
      Yes we want more!!

      Comment


        #4
        stop the hacker attmet here......
        Code:
        #!/usr/local/bin/perl
        # htaccess password protector
        
        ########################################################################
        #
        ########################################################################
        #
        # You need to modify $formloc, $basedir, $correctpass, $emailfrom
        # Be sure to upload the script in ASCII mode
        # The very first line of the script points to where perl is installed on your server
        # 
        
          #
          # URL where the script is located
          #
          $formloc = "http://yoursite.com/htaccess/admin.cgi";
        
          # The base directory is the directory one level up from where you will be securing
          # the sub-directories.
          # if you want to secure /home/user/members then the base directory will be /home/user/
          #
          #
          # Physical drive path to the script
          # Don't forget the / at the end
          #
          $basedir = "/u/web/tech12/htaccess/";
          
          #  use [url]http://yoursite.com/crypt.cgi?password  for[/url] new one
          #  example [url]http://yoursite.com/crypt.cgi?camel[/url]
          #  Then copy and paste the encrypted results below ...
          #
          $correctpass = "aaqPiZY5xR5l.";  # password is test
        
          # no need to change .. but you can use any file name for storing passwords
          #
          # On some servers, you may need to upload a blank .htpasswd file into the directory
          # you are protecting and chmod it to 777
          #
          $htpasswdname = ".htpasswd";
          
          $scrollsize = 10;                    # how big the user list menu will be
          $mailprog = '/usr/lib/sendmail';     # where sendmail is on your server
        
          # when e-mails are sent out, what will show in the From field
          # Don't forget the \ before the @ in the e-mail address
          #
          $emailfrom = "sammy\@yoursite.com (site name)"; 
        
          # Subject of the e-mails
          #
          $emailsubject = "Your Access Account";
        
          $emailtop = "Text to be placed at the top of the e-mail \n\n";
          $emailbottom = "\n\nText to be placed at the bottom of the e-mail \n\n";
        
          &parse_form;
        
          # only here for demo
          #$FORM{'targetdir'} = "secure";
        
          # strip funny characters off
          # this prevents you from typing in /directory/directory2 in the script
          # if you do want to be able to protect sub-sub directories then put a #
          # infront of each of the targetdir lines
          #
          $FORM{'targetdir'} =~ s/\\//g;
          $FORM{'targetdir'} =~ s/\///g;
          $FORM{'targetdir'} =~ s/\|//g;
          $FORM{'targetdir'} =~ s/\;//g;
        
        
          # do not change
          $htpasswdloc = "$basedir$FORM{'targetdir'}/$htpasswdname";
        
          print "Content-type: text/html\n\n";
          #
          # Check if only the admin can use
          #
          if (crypt($FORM{'password'},"aa") ne $correctpass) {
            &askforpass;
            exit;
          }
        
          print "<HTML><TITLE>Techno Trade&#39;s Password Editor</TITLE><BODY BGCOLOR=#FFFFFF>\n";
        
        
          if ($FORM{&#39;targetdir&#39;} eq "") {
            &refresh;
            exit;
          }
          &adduser if (($FORM{&#39;action&#39;} eq "ADD") && ($FORM{&#39;targetdir&#39;} ne ""));
          &deleteuser if (($FORM{&#39;action&#39;} eq "DELETE") && ($FORM{&#39;targetdir&#39;} ne ""));
          &generatehtaccess if (($FORM{&#39;action&#39;} eq "GEN") && ($FORM{&#39;targetdir&#39;} ne ""));
          &extractemails if (($FORM{&#39;action&#39;} eq "EMAILS") && ($FORM{&#39;targetdir&#39;} ne ""));
        
          &addinfo;
        
          &listusers;
        
          &print_end;
        
          exit;
        
        #########################################
        sub addinfo {
        
        print<<ADDINFO;
          <FONT SIZE=5 COLOR=000080 FACE="VERDANA, ARIAL, HELVETICA">[b]Password editor[/b]</FONT>
        
        
          <FONT SIZE=4 COLOR=000080 FACE="VERDANA, ARIAL, HELVETICA">[b]Add User[/b]</FONT>
          <PRE><FORM METHOD=POST ACTION="$formloc">
          username  : <INPUT NAME="username" SIZE=20> password  : <INPUT TYPE=password SIZE=20 name="pass">
          name      : <INPUT SIZE=20 name="name"> email     : <INPUT SIZE=30 name="email">
          comments  : <INPUT SIZE=30 name="comments">
          <INPUT TYPE="CHECKBOX" NAME="sendemail" VALUE="Y">       : Check to e-mail new entry to user
          Extra E-mail Text : 
                      <TEXTAREA NAME="extratext" COLS=50 ROWS=4></TEXTAREA>
          </PRE>
          <INPUT TYPE="hidden" NAME="password" VALUE="$FORM{&#39;password&#39;}">
          <INPUT TYPE="hidden" NAME="targetdir" VALUE="$FORM{&#39;targetdir&#39;}">
          
          <INPUT TYPE="submit" Value="Add User">
          <INPUT TYPE="hidden" NAME="action" VALUE="ADD">
        
          </FORM>
        ADDINFO
        
        }
        
        
        ####################################
        #
        # Print Footer Info
        #
        sub print_end {
         &refresh;
        print<<RELO1;
         <HR noshade>
         <FONT SIZE=4 COLOR=000080 FACE="VERDANA, ARIAL, HELVETICA">
         [b]Generate .htaccess file[/b]</FONT>
         <FORM METHOD="POST" ACTION="$formloc">
         <PRE><INPUT TYPE="hidden" NAME="password" VALUE="$FORM{&#39;password&#39;}">
         Directory : <INPUT NAME="targetdir" VALUE="$FORM{&#39;targetdir&#39;}">
         </PRE>
         <INPUT TYPE="hidden" NAME="action" VALUE="GEN">
         <INPUT TYPE="submit" Value=" Generate ">
         </FORM>
         
        
         This will display what your .htaccess file should look like for the above directory
        
         Just copy and paste the results of this to a text editor, save the file as .htaccess and
         upload to the directory you wish to password protect. (Use your browser&#39;s back button to return) 
         <HR noshade>
         <FONT SIZE=4 COLOR=000080 FACE="VERDANA, ARIAL, HELVETICA">
         [b]Extract E-mails[/b]</FONT>
         <FORM METHOD="POST" ACTION="$formloc">
         <INPUT TYPE="hidden" NAME="password" VALUE="$FORM{&#39;password&#39;}">
         <INPUT TYPE=HIDDEN NAME="targetdir" VALUE="$FORM{&#39;targetdir&#39;}">
        
         <INPUT TYPE="hidden" NAME="action" VALUE="EMAILS">
         <INPUT TYPE=CHECKBOX NAME="comma" VALUE="Y"> Add a comma after each line ?
        
         <INPUT TYPE="submit" Value=" Extract E-mails ">
        
        
         This feature is used to pull all the e-mail address from your member list.
         You can then copy and paste the list to your favorite e-mail program.
         </FORM>
         
        
        
        
        RELO1
        
          print "
        <CENTER><A HREF=\"http://yoursite.com\">Techno Trade Online Solutions</A> \\\ <A HREF=\"http://yoursite.com/htaccess/\">Script Home</A>
        \n";
          print "</CENTER>\n";
          print "</BODY></HTML>\n";
        }
        
        ############
        sub refresh {
         print<<REFRE1;
         <HR noshade>
         <FONT SIZE=4 COLOR=000080 FACE="VERDANA, ARIAL, HELVETICA">
         [b]Refresh Screen[/b]</FONT>
        
         Change to a directory which you want password protected
         
         <FORM METHOD="POST" ACTION="$formloc">
         <PRE><INPUT TYPE="hidden" NAME="password" VALUE="$FORM{&#39;password&#39;}">
         Directory : <INPUT NAME="targetdir" VALUE="$FORM{&#39;targetdir&#39;}">
         </PRE>
         <INPUT TYPE="submit" Value=" Refresh ">
         </FORM>
        REFRE1
        }
        
        ############
        sub askforpass {
         print<<REFRE1;
         <HR noshade>
         <FONT SIZE=4 COLOR=000080 FACE="VERDANA, ARIAL, HELVETICA">
         [b]Enter your password/directory[/b]</FONT>
        
         <FORM METHOD="POST" ACTION="$formloc">
         <PRE>
         Password  : <INPUT NAME="password" SIZE=20>
         Directory : <INPUT NAME="targetdir" SIZE=30>
         </PRE>
         <INPUT TYPE="submit" Value=" Refresh ">
         </FORM>
        REFRE1
        }
        
        
        #####################################
        #
        # Prints the bottom box showing path and .htaccess format
        #
        sub generatehtaccess {
        
        
          print "<PRE>";
          print "AuthName Protected-Directory\n";
          print "AuthType Basic\n";
          print "AuthUserFile $basedir$FORM{&#39;targetdir&#39;}/$htpasswdname\n";
          print "&lt;limit GET POST>\n";
          print "require valid-user\n";
          print "&lt;/limit>\n";
          print "</PRE>\n";  
        
          exit;
        }
        
        ###########################################
        #
        #  List users
        #
        sub listusers {
        
          local($user,$counter,$x);
          if (!(-e $htpasswdloc)) {
            $counter = 0;
            return;
          }
         
          print "<HR noshade><FONT SIZE=4 COLOR=000080 FACE=\"VERDANA, ARIAL, HELVETICA\">[b]List Users[/b]</FONT>
        
        \n";
          print "<FORM METHOD=\"POST\" ACTION=\"$formloc\">\n";
        
          open(FILE,$htpasswdloc);
          flock(FILE,2);
          @USERS = <FILE>;
          close(FILE);
        
          foreach $us (@USERS) {
            if (substr($us,0,1) ne "#") {
              ($user,$pass) = split (":",$us,2);
              push(@USERLIST,$user);
            } else {
              $commentline = substr($us,1);
              ($user,$name,$email,$comments,$extra) = split(/\s*\|\s*/,$commentline,5);
              $USERINFO{$user} = $commentline;
            }
          }
        
          #
          # Sort by username
          #
          @USERLIST = sort {$a cmp $b} @USERLIST;
        
          print "<SELECT NAME=\"username\" SIZE=$scrollsize>\n";
        
          foreach $user (@USERLIST) {
            print "<OPTION VALUE=\"$user\">$user";
            if ($USERINFO{$user}) {
               ($user,$name,$email,$comments,$extra) = split(/\s*\|\s*/,$USERINFO{$user},5);
               print " - $name - $email - $comments\n";
            }
          }
        print<<LU1;
        </SELECT>
        <INPUT TYPE="hidden" NAME="action" VALUE="DELETE">
        <INPUT TYPE="hidden" NAME="password" VALUE="$FORM{&#39;password&#39;}">
        <INPUT TYPE="HIDDEN" NAME="targetdir" VALUE="$FORM{&#39;targetdir&#39;}">
        
        
        <INPUT TYPE=\"submit\" Value=\"Delete User (Select one from list)\">
        
        
        
        Or Select a User to modify password
        
        New Password : <INPUT TYPE=PASSWORD NAME="newpass" SIZE=20>
        
        <INPUT TYPE="CHECKBOX" NAME="sendemail" VALUE="Y">       : Check to e-mail modification to user
        
        
        <INPUT NAME="modbutton" TYPE=\"submit\" Value=\"Modify Password">
        </FORM>
        LU1
        }
        
        ###########################################
        #
        #  Extract E-mails
        #
        sub extractemails {
        
          local($user,$counter,$x);
          if (!(-e $htpasswdloc)) {
            $counter = 0;
            return;
          }
         
          open(FILE,$htpasswdloc);
          flock(FILE,2);
          @USERS = <FILE>;
          close(FILE);
          print "Extracting E-mails ... 
        
        ";
          foreach $us (@USERS) {
            if (substr($us,0,1) eq "#") {
              $commentline = substr($us,1);
              ($user,$name,$email,$comments,$extra) = split(/\s*\|\s*/,$commentline,5);
              if ($email =~ /\@/) {
                 print "$email";
                 print "," if ($FORM{&#39;comma&#39;} eq "Y");
                 print "
        \n";
              }
            }
          }
          exit;
        }
        
        
        ###################################################
        #
        # Delete User
        #
        sub deleteuser {
        
          open(FILE,$htpasswdloc);
          flock(FILE,2);
          @USERS = <FILE>;
          close(FILE);
        
          open(FILE,">$htpasswdloc");
          flock(FILE,2);
          $counter = @USERS;
          for ($x=0; $x < $counter; $x++) {
            if (substr($USERS[$x],0,1) ne "#") {
              ($user,$pass) = split (":",$USERS[$x],2);
            } else {
              $commentline = substr($USERS[$x],1);
              $commentline =~ s/\n//g;
              ($user,$name,$email,$comments,$extra) = split(/\s*\|\s*/,$commentline,5);
              if ($FORM{&#39;username&#39;} eq $user) {
                $deluser = $user;
                $delname = $name;
                $delemail = $email;
                $delcomments = $comments;
                $delextra = $extra;
              }
            }
            print FILE "$USERS[$x]" if ($user ne $FORM{&#39;username&#39;});
          }
        
          if (($FORM{&#39;username&#39;} ne "") && ($FORM{&#39;modbutton&#39;} eq "Modify Password") && ($FORM{&#39;newpass&#39;} ne "")) {
            print FILE
            join (":", $deluser, crypt($FORM{&#39;newpass&#39;},"aa")), "\n";
            print FILE "#$deluser|$delname|$delemail|$delcomments|$extra\n";
            if (($FORM{&#39;sendemail&#39;} eq "Y") && ($delemail =~ /\@/)) {
               &send_email($delemail,$deluser,$FORM{&#39;newpass&#39;},"");
            }
          }
          close(FILE);
        
        }
        
        #################################################
        #
        # Add user to the file
        #
        sub adduser {
        
          $FORM{&#39;pass&#39;} =~ s/\n//g;
          $FORM{&#39;email&#39;} =~ s/\n//g;
          $FORM{&#39;name&#39;} =~ s/\n//g;
          $FORM{&#39;comments&#39;} =~ s/\n//g;
          $FORM{&#39;pass&#39;} =~ s/\|//g;
          $FORM{&#39;email&#39;} =~ s/\|//g;
          $FORM{&#39;name&#39;} =~ s/\|//g;
          $FORM{&#39;comments&#39;} =~ s/\|//g;
        
          
          &endscript("Username must be lowercase alphabetic + numeric!")
            unless $FORM{&#39;username&#39;} =~ /^[a-z,0-9]+$/;
        
          &endscript("Your must enter a password!")
            unless $FORM{&#39;pass&#39;} =~ /\S/;
        
        
          open (PW, "+>>$htpasswdloc") ||
          &endscript("Cannot Locate $htpasswdloc: $!");
          flock (PW, 2);            
          seek (PW, 0, 0);
          while (<PW>) {
            my ($user) = split ":";
            &endscript("sorry, that username is already taken") if $user eq $FORM{&#39;username&#39;};
          }
        
          seek (PW, 0, 2);        # end of file
          $password = $FORM{&#39;pass&#39;};
          print PW
          join (":", $FORM{&#39;username&#39;}, crypt($password,"aa")), "\n";
          print PW "#$FORM{&#39;username&#39;}|$FORM{&#39;name&#39;}|$FORM{&#39;email&#39;}|$FORM{&#39;comments&#39;}|0\n";
          close PW;
          
          if (($FORM{&#39;sendemail&#39;} eq "Y") && ($FORM{&#39;email&#39;} =~ /\@/)) {
             &send_email($FORM{&#39;email&#39;},$FORM{&#39;username&#39;},$FORM{&#39;pass&#39;},$FORM{&#39;extratext&#39;});
          }
        
        }
        ####################################################
        sub send_email {
          local($uemail,$uname,$upass,$extratext) = @_;
        
          open(MAIL, "|$mailprog -t") || die "Can&#39;t open $mailprog!\n";
          print MAIL "To: $uemail\n";
          print MAIL "From: $emailfrom\n";
          print MAIL "Subject: $emailsubject\n\n";
          print MAIL "$emailtop";
          print MAIL " Username : $uname\n";
          print MAIL " Password : $upass\n\n";
          print MAIL "$extratext\n";
          print MAIL "$emailbottom";
          close(MAIL);
        }
        
        ####################################################
        sub endscript {
          local ($str) = @_;
        
          print " $str 
         \n";
          exit;
        
        }
        
        #####################################################
        #
        # Parse Form Data
        #
        sub parse_form {
        
           read(STDIN, $buffer, $ENV{&#39;CONTENT_LENGTH&#39;});
           if (length($buffer) < 5) {
                 $buffer = $ENV{QUERY_STRING};
            }
           @pairs = split(/&/, $buffer);
           foreach $pair (@pairs) {
              ($name, $value) = split(/=/, $pair);
        
              $value =~ tr/+/ /;
              $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
        
              $FORM{$name} = $value;
           }
        }
        place this is admin.cgi)

        then in htaccess file <? incude(&#39;admin.cgi&#39;); ?>

        make one file name txt htaspass put your pass there $htaccess=password
        Visit: Chat4u.mobi - The New Lay Of being a site of your dreams!
        Visit: WapMasterz Coming Back Soon!
        _______
        SCRIPTS FOR SALE BY SUBZERO
        Chat4u Script : coding-talk.com/f28/chat4u-mobi-script-only-150-a-17677/ - > Best Script for your site no other can be hacked by sql or uploaders.
        FileShare Script : coding-talk.com/f28/file-wap-share-6596/ -> Uploader you will never regret buying yeah it mite be old now but it still seems to own others...
        _______
        Info & Tips
        php.net
        w3schools.com

        Comment


          #5
          What means
          Code:
          addtype audio/x-mpegurl m3u
          addtype audio/mpegurl m3u
          addtype text/vnd.wap.wml wml
          addtype application/vnd.wap.wmlc wmlc
          addtype text/vnd.wap.wmlscript wmls
          addtype application/vnd.wap.wmlscriptc wmlsc
          addtype image/vnd.wap.wbmp wbmp
          addType application/java-archive jar
          addType application/x-java-archive jar
          addType text/vnd.sun.j2me.app-descriptor;charset=UTF-8 jad
          addType application/vnd.symbian.install sis
          addType audio/3gpp 3gp
          addType video/3gpp 3gp
          addType audio/x-wav wav
          addType audio/amr amr
          addType audio/amr-wb awb
          addType audio/mpeg mp3
          addType audio/x-midi mid
          addType audio/midi mid
          addType audio/midi midi
          addType application/x-smaf mmf
          addType application/vnd.smaf mmf
          addType application/vnd.mophun.application mpn
          addType application/vnd.mophun.application mpc
          addType application/vnd.eri.thm thm
          addType application/vnd.nok-s40theme nth
          ?? For what is it ?

          Comment


            #6
            What means
            Code:
            addtype audio/x-mpegurl m3u
            addtype audio/mpegurl m3u
            addtype text/vnd.wap.wml wml
            addtype application/vnd.wap.wmlc wmlc
            addtype text/vnd.wap.wmlscript wmls
            addtype application/vnd.wap.wmlscriptc wmlsc
            addtype image/vnd.wap.wbmp wbmp
            addType application/java-archive jar
            addType application/x-java-archive jar
            addType text/vnd.sun.j2me.app-descriptor;charset=UTF-8 jad
            addType application/vnd.symbian.install sis
            addType audio/3gpp 3gp
            addType video/3gpp 3gp
            addType audio/x-wav wav
            addType audio/amr amr
            addType audio/amr-wb awb
            addType audio/mpeg mp3
            addType audio/x-midi mid
            addType audio/midi mid
            addType audio/midi midi
            addType application/x-smaf mmf
            addType application/vnd.smaf mmf
            addType application/vnd.mophun.application mpn
            addType application/vnd.mophun.application mpc
            addType application/vnd.eri.thm thm
            addType application/vnd.nok-s40theme nth
            ?? For what is it ?[/b]

            so if u have download at ur site....

            if u attempt 2 download 4 axample *.jar file with phone without tht in .htaccess ull get it as *.txt file.......
            sigpiceeeeerrr....

            Comment


              #7
              Ok , tnx, i understood ...

              Comment


                #8
                Best way is to search google for .htaccess tips and tricks :-)

                Comment


                  #9


                  thanks nice post

                  Comment

                  Working...
                  X