I am developing a site with user accounts. The URL for each is along the lines of:
www.site.com/profile.php?user=ChanceM
But, I was wondering if there was another way to send values through the URL and grab them with PHP with a URL more like this:
www.site.com/ChanceM
Or:
www.site.com/profile.php/ChanceM
I was just wondering if this were possible, because remembering the first URL isn't very user friendly. Thanks!
For Apache yes - You need to look through the manual pages for rewrite rules. The link will tell you how to do this. Also look through the Apache documentation.
As for other servers I do not know.
There are certainly ways to do this but maybe not built right into php like the $_GET array is. One thing you can do is in the apache configuration, replace the 404 page with a php script which gets url aimed at and redirects to a version like www.site.com/profile.php?user=ChanceM (and I think in mod_rewrite you can do this too).
Yes, you can do it any of the ways you illustrated.
In the case of the first example, you have to use something like mod_rewrite which can transparently rewrite the friendly URL (site.com/Username) to the PHP script (site.com/profile.php?user=Username)
Using the second method, you have to use $_SERVER['REQUEST_URI']
to access the data from the URL, and manually parse it into usable variables.
If you want to send "cleaner URL's" (Without doing some type of URL rewrite) you can use things like implode and parse url:
http://us2.php.net/manual/en/function.parse-url.php
http://us2.php.net/manual/en/function.implode.php
These methods allow you to pull various parts of the URL and use them
You want to use mod_rewite
in Apache.
Here's an example of a rewrite rule RewriteRule ^(.*)$ profile.php?user=$1
You can test it here: http://martinmelin.se/rewrite-rule-tester/