It seems like there ought to be an easy answer to this one, but it's escaping me and I'd really appreciate some help!

I want a client to enter his name and be redirected to a folder having that name. For example, on mydomain.com/clients/redirect.htm he is presented with a name box. He enters "george" in the box and is redirected to mydomain.com/clients/george/mypage.htm.

(I have the password protection of the folders covered, and I am currently using an alphabetic list of names to choose from, but some clients would rather other clients not be able to see the whole client list.)

I'm using an Apache server.

1. What is the best way to input the client name?

2. How can I use the input information to build the correct hyperlink?

I'd say use PHP and mySQL to pull it off properly.

Here is a bit of an example

Create the following table in a database called "client_list"

-- Database: `client_list`
--

-- --------------------------------------------------------

--
-- Table structure for table `clients`
--

CREATE TABLE IF NOT EXISTS `clients` (
  `clientid` int(25) NOT NULL AUTO_INCREMENT,
  `username` varchar(25) NOT NULL,
  `password` varchar(255) NOT NULL,
  PRIMARY KEY (`clientid`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;

--
-- Dumping data for table `clients`
--

INSERT INTO `clients` (`clientid`, `username`, `password`) VALUES
(1, 'test', 'test');

Now create the following PHP call it "process.php"

<?php

	//Database Information
	$dbhost = "localhost";
	$dbname = "client_list";
	$table = "clients"; // added this incase you change the table name
	$dbuser = "root";
	$dbpass = "";	

	//Connect to database
	mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
	mysql_select_db($dbname) or die(mysql_error());
	
	session_start();
	$username = $_POST['username'];
	$password = $_POST['password'];	
	$query = "SELECT  * FROM $table WHERE username='$username' and password='$password'";

	$result = mysql_query($query);

	//Get current directory
	$user = $username;
	$defaultuserfile = "mypage.htm";
	$writefilename = $user."/".$defaultuserfile;

	//What we do if its a bad login
	if (mysql_num_rows($result) != 1) {
		$error = "Bad Login";
		echo "$error";
	
	} else {
	    $_SESSION['username'] = "$username";
		ob_start();
		header("Location:$writefilename");
		ob_flush();
	}	

?>

Finally add the login form

<h3>Example </h3>

<form name="login" method="post" action="process.php">
            <table border="0" width="220">
                <tr>
                    <td width="71"><span style="font-size:10pt;">Username:</span></td>
                    <td width="139"><input type="text" name="username"></td>
                </tr>
                <tr>
                    <td width="71"><span style="font-size:10pt;">Password:</span></td>
                    <td width="139"><input type="password" name="password"></td>
                </tr>
                <tr>
                    <td width="71">&nbsp;</td>
                        <td width="139">
                            <p align="right"><input type="submit" name="submit" value="Submit" src="login.php"></p>
                        </td>
                </tr>
            </table>
</form>

Thats it... should do the trick. If you want to change the default user page, just change the "defaultuserfile " varible in process.php

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.