Also, do I need to create a subdomain for each user? I'm not sure what you meant in this statement:
"You need DNS for the subdomains.
Each user needs a subdoamin created, or you can have Wildcard DNS where any subdoamin will work.
The subdomains need to point to your main document root."
When you go to the subdomains (without any mod_rewrite), they need to go to the same files as your main domain does.
am going to pull the username and id from the database.
If you're doing a database query you don't need the array, something like this:
- Code: Select all
<?php
# check for username
if(!isset($_GET['mr_user']))
{
header('Location: http://' . getenv('HTTP_HOST') . '/', true, 301);
exit();
}
# connect to database server
if(!($mr['con'] = mysql_connect('localhost', 'mysql_user', 'mysql_password')))
{
exit('Could not connect to MySQL server: ' . mysql_error());
}
# select database
if(!mysql_select_db('foo', $mr['con']))
{
exit('Could not select database: ' . mysql_error($mr['con']));
}
# clean the input
$mr['un'] = mysql_real_escape_string(trim($_GET['mr_user']));
unset($_GET['mr_user'])
# search for user's ID
if(!($mr['res'] = mysql_query('SELECT ownerid FROM site_users WHERE sitename="'
. $mr['un'] . '" LIMIT 1', $mr['con'])))
{
exit('MySQL query failed: ' . mysql_error());
}
# put user's ID in the userid GET variable
$mr['res2'] = mysql_fetch_assoc($mr['res']);
# no userid
if(empty($mr['res2']))
{
header('Location: http://' . getenv('HTTP_HOST') . '/', true, 301);
exit();
}
$_GET['userid'] = $mr['res']['ownerid'];
# get the filename
$mr_uri = explode('?', getenv('REQUEST_URI'));
unset($_GET['mr_user'], $mr);
# include the file
include(getenv('DOCUMENT_ROOT') . $mr_uri[0]);
It isn't tested though, but it's the basic idea.