Results 1 to 5 of 5
  1. #1

    send users to different pages with htaccess

    I need to send users to their own pages when they enter username. How can i do that?

    eks.
    User logs on with username: user1 under "www/domain.com", and that user will sendt to his own page "www/domain.com/users/user1.htm"

  2. #2
    Join Date
    Sep 2003
    Location
    Texas
    Posts
    16
    bazzo
    I am trying to do this also. Did you ever find a way to do this?

    jumpdawg

  3. #3
    index.php
    Code:
    <?php 
    $path = "/home/bah/www/users"; 
     
    if($user != "") { 
      mt_srand((double)microtime()*1000000);  
      $chars = array_merge(range('a','z'),range('A','Z'),range(0,9));  
      for($i=0;$i<2;$i++) {  
        $salt .= $chars[mt_rand(0,count($chars)-1)]; 
      } 
      $pass = crypt($pass, $salt); 
     
      if (!$fd = fopen($path . "/" . $user . "/.htaccess", "w")) { 
        print "Cannot open .htaccess file"; 
        exit; 
      } 
     
      if (!fwrite($fd, "AuthName \"Protected Area\"\n 
                   AuthUserFile ". $path . "/" . $user . "/.htpasswd\n 
                   AuthType Basic\n\n 
     
                   <Limit GET>\n 
                   require valid-user\n 
                   </Limit>")) { 
        print "Cannot write to .htaccess file"; 
        exit; 
      } 
      fclose($fd); 
     
     
      if (!$fd = fopen($path . "/" . $user . "/.htpasswd", "w")) { 
        print "Cannot open .htpasswd file"; 
        exit; 
      } 
     
      if (!fwrite($fd, $user.":".$pass)) { 
        print "Cannot write to .htpasswd file"; 
        exit; 
      } 
      fclose($fd); 
     
      echo "User added.<BR><BR>"; 
    } else { 
    ?> 
    <H1>This sets up the htaccess for the given user</h1> 
    Directory must already be created <i>and chmod'ed 777</i><br> 
    <form name="form1" method="post" action="<?php echo $PHP_SELF; ?>"> 
    <p> 
      User: <input name="user" type="text" id="user" value=""> 
    </p> 
    <p>&nbsp; </p> 
    <p> 
      Pass: <input name="pass" type="text" id="pass" value=""> 
    </p> 
    <p> 
      <input type="submit" name="Submit" value="Submit"> 
    </p> 
    </form> 
    <p>&nbsp;</p> 
    <?php 
    } 
    ?>
    Not sure if this is what you're looking for but might set you into the right direction, this was for what you're trying to do.
    dotGig
    <:<: [Fruit eating linux administrator]

  4. #4
    Join Date
    Sep 2003
    Location
    Texas
    Posts
    16
    Thanks
    I will try this and see if I can get it to work.
    Jumpdawg

  5. #5
    Join Date
    Jul 2003
    Location
    Kuwait
    Posts
    5,104
    Perhaps a more simple solution :

    PHP Code:
    <?php
        
    if ($_SERVER['REQUEST_METHOD'] == "POST")
        {
              
    $username $_POST['username'];
              
    $password $_POST['password'];
        } else {
              exit(
    "Sorry, you must login first");
        }
        
    //Add your username checking code
        //here. This is just an example

        
    if(!mysql_connect("localhost","user","pass")) { die(mysql_error()); }
        if (!
    mysql_select_db("user_database")) { die(mysql_error()); }
        
        
    $query "SELECT * FROM users WHERE username = '".$username."' AND pass = '".md5($password)."'";
        if (!
    $res mysql_query($query)) { die($query."<br />".mysql_error()); }
        if (
    mysql_num_rows($res) == 0)
        {
             echo 
    "Sorry, your credentials aren't valid";
         } else {
            
    header("Location: http://host.sld.tld/users/".$username.".html");
            exit();
         }
    ?>
    Of course, you'd replace the validation code with something that works for your situation. You would call this script from your login form, something like this:
    Code:
    <form method="post" action="nameoffile.php">
    <input type="text" name="username" />
    <input type="password" name="password" />
    <input type="submit" name="submit" value="Login" />
    </form>

Posting Permissions

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