Results 1 to 5 of 5
-
05-12-2004, 07:11 AM #1New Member
- Join Date
- May 2004
- Posts
- 3
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"
-
06-12-2004, 01:08 AM #2
bazzo
I am trying to do this also. Did you ever find a way to do this?
jumpdawg
-
06-12-2004, 01:27 AM #3Web Hosting Master
- Join Date
- May 2002
- Posts
- 3,416
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> </p> <p> Pass: <input name="pass" type="text" id="pass" value=""> </p> <p> <input type="submit" name="Submit" value="Submit"> </p> </form> <p> </p> <?php } ?>
dotGig
<:<: [Fruit eating linux administrator]
-
06-12-2004, 11:51 AM #4
Thanks
I will try this and see if I can get it to work.
Jumpdawg
-
06-12-2004, 12:18 PM #5Web Hosting Master
- 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();
}
?>
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>