Forum Moderators: coopster
I'm not sure exactly what to call this process/script idea I am looking for, so I outline the situation here:
1) Users create a web page using a PHP-based form I created. All data entered into the form is stored in a MySQL database TABLE on the server. All users have unique names.
2) Users then should be able to share their web page with others by offering them a URL which contains the user's username [ e.g. members.site.com/username ]
3) How do I obtain the "username" part of a URL (the URI?) and using that "username", build the page with this query (assuming the query is syntactically correct) <? mysql_query ("SELECT * FROM members WHERE username = ." . $username "'");?>
MUCH much thanks for anyone's help ... my small project is all-but-for-this finished ... HELP!
take care,
not_a_bozo
My mod_rewrite compratriots may offer that or some crazy regex as your answer but I will offer a couple of possibilities off the top of my head.
this is what I have
$url="www.xyz.com/username";
how you get the url in there will change some of the below functions
$username=strstr [php.net]($url,"/");
that should return "/username" and you could cut the first char out after
$username=substr [php.net]($url,13);
should return from the 13th char on, which in that format would be the username
$temp=split [php.net]("/",$url);
$username=$temp[1];
should return whatever is after the first slash
my main point here is that there are always many ways to do things. Hopefully some regex and mod_rewrite answers will also be offered. Then we could see the true extent of this statement. ;) It mostly depends on what you are comfortable with and the data you are dealing with.
I've looked over the lines of script you offer and they seem pretty straightforward to me.
However, as more information, when I have entered a URL such as.... members.mysite.org/username ... an error appears with "no such file" (or some such rejection/error notice) ... to which I am sent reeling with frustration. I just cannot seem to be able to get my head around this problem!
the problem I see (and this may reveal my neophyte status) is that there is no "name.html" just a "username" following the members.mysite.org URL address.
How does one get past this?
What am I missing or overlooking?
(As I said, I am a neophyte in this area...) 8-)
Thanks again to you, Jatar_k ... and to anyone else who joins the fray with other answers or ideas.
not_a_bozo
(glen)
We go for mod_rewrite [httpd.apache.org] then.
This is not my area of expertise but I might be able to give you some basics. Regardless of the format but let's use this one, www.xyz.com/username.
You need a method to make sure that if someone requests the above url that is sent to a script that can grab the username and forward them to the appropriate directory for that user. (I am assuming here)
You could take a look at this thread until someone more adept in the area chimes in
An Introduction to Redirecting URLs on an Apache Server [webmasterworld.com]
Set up a "wildcard dns" that points *.yourdomain.com to the server IP address.
Then set up an apache virtualhost :
<VirtualHost 12.131.12.1>
ServerName users.yourdomain.com
ServerAlias *.yourdomain.com
DocumentRoot "/your/directory/usersfile.php"
</VirtualHost>
Then, you can use "username.yourdomain.com" and all requests will be sent to "usersfile.php" - no mod-rewite needed!
the problem with jamesa is it will rewite everything after the / which won't be so cool if you have a directory called "images" or something, and also requires a trailing slash ( so yourdomain.com/username won't work, only yourdomain.com/username/ ).
This rewrite script will only take effect if you don't have a directory or file called "username".
Here is my modrewrite rule:
RewriteEngine on
# if requested resource doesn't exist
RewriteCond /%{REQUEST_FILENAME}!-f
# redirect to default image
RewriteRule ^(.+) /pagecreatingscript.php
This forum deletes spaces before '!'s so add a space before the '!'
Now, with respect to all three of you who have responded, I have been able to get a call to one page to be redirected to another page using the following .htaccess within one
cd0
directory:
Options FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^members.sitename.org [NC]
RewriteCond %{REQUEST_URI} ^/index.php [NC]
RewriteRule ^(.*) http://www.sitename.com [L]
Now, trying to get the {REQUEST_URI} line to accept a simple 'username' instead of some sort of filename.html or filename.php
AND, to be able to take that 'username' (a unique value in a database TABLE containing the user's web page parameters which will be used to dynamically build their single page within my site) and pass it (as seen passed in the Browser Address Bar) like this: http://members.sitename.org/?userwebpage=$username
Does this make sense? ... Y'all are in the ballpark with information (referring me to the tutorial elsewhere on this site, which in turn referred me to the Apache site was brilliant!) ... and the scripting lines .. and comments ... I'm slowly putting this all together and will eventually crack this nut!
Thanks again. I am posting this reply to alert you of the slow and sure movement of achieving my goal and to thank you (again and again) and to inspire any other comments/help!
Much appreciated,
not_a_bozo
[edited by: jatar_k at 4:42 am (utc) on April 2, 2003]
[edit reason] no specifics please [/edit]