Im very experienced in PHP and know some asp. But ive never coem across how to do this. I want it so when a user signs up to my aite a file is created on my site of which its name is their username. This way they can view there "profile" by typing in mysite.com/FILENAME.php.
Doe anyone know how to do this?
How to make files the names of users (like myspace) in PHP?
This has nothing to do with PHP; it is strictly a system administration task.
Normally, this is handled using URL rewriting. For example, if the server receives a request for
mysite.com/someuser
it actually displays, say,
mysite.com/profile.php?user=someuser
The user still sees mysite.com/someuser in the address bar, as this is a rewrite rather than redirection.
To use URL rewriting, you need Apache with mod_rewrite enabled.
How to make files the names of users (like myspace) in PHP?
One way is to use Apache URL rewriting rules, so requests are redirected to one PHP script with the name as a parameter.
The other is to use a slightly different URL scheme, e.g. example.org/?username (note the ? ) which would pass the username to index.php , and have the advantage that if you switched later to (say) a Ruby on Rails backend, the URLs won't change.
How to make files the names of users (like myspace) in PHP?
Sometimes web hosts do not give you full control of your web site so modifying Apache is not always possible. Wouldn't being able to leave off the .php be better. Such as:
http://mySite.com/JamesDean
Since the page does not exist, the e404html page will be called. Redirect to e404.php and parse the URL and see if JamesDean is a member, if so redirect again to Jimmy's page, if not then it really is a e404 error and handle appropriately.
How to make files the names of users (like myspace) in PHP?
Server rules should work
You should be able to set what files are interpreted as php so you could do something like
mysite.com/your.name/FILENAME
If you have Linix/Unix server you can create .htaccess file to interpret .name files with this declaration
AddType application/x-httpd-php .name
Here is a tutorial
http://www.translatum.gr/forum/index.php...
If you are on a virtual server or shared host you may or may not be able to do this
Another way to do it is as a rewrite rule:
RewriteEngine on
RewriteRule ^name/.+$ /name.php?filename=$1
for something like
mysite.com/name/FILENAME
will be taken to
mysite.com/name.php? filename=FILENAME
No comments:
Post a Comment