ali_kiyani Posted July 30, 2007 Share Posted July 30, 2007 Hi I have a web page where user registers. Each member is given its own URL based on the user name he gives during sign up. So for e.g. if some one entered "Smarty" then his web page URL will become http://www.mywebsite.com/Smarty On this page user's image and other details are shown. So if my website has 1000 users then 1000 URLs will be created like above. How can I do this in PHP? Shall I use MOD_REWRITE or there is some other solution? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/62446-mod_rewrite-or-some-other-method/ Share on other sites More sharing options...
wildteen88 Posted July 30, 2007 Share Posted July 30, 2007 When a user signs up you'd add all their info into the database then using 1 php page, call this user.php, which takes a url parameter called userid the userid holds the username which is passed to user.php like this: user.php?userid=Smarty then in user.php you use $_GET['userid'] to get the username from the userid URL parameter. Using that userid you'd query your database to fetch what ever information you want to be shown for that user. To get urls like this to work: mysite.com/Smarty You'd want to use mod_rewrite: RewriteEngin On RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([a-z0-9]+)$ user.php?userid=$1 [NC, L] Quote Link to comment https://forums.phpfreaks.com/topic/62446-mod_rewrite-or-some-other-method/#findComment-310803 Share on other sites More sharing options...
ali_kiyani Posted July 30, 2007 Author Share Posted July 30, 2007 Ok I did as you said. Opened .htaccess file and wrote that code in it (there was already some code written in that file so I appended it with new code) Then I created a file user.php for testing in which I wrote if($HTTP_GET_VARS["userid"] == "1") print "ONE"; else print "TWO"; Now when I run this page http://www.mywebsite.com/user.php?userid=1 then I get the following error Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator, webmaster@mywebsite.com and inform them of the time the error occurred, and anything you might have done that may have caused the error. More information about this error may be available in the server error log. Not only that the other PHP pages in the same directory which were working previously are also showing the same error. Quote Link to comment https://forums.phpfreaks.com/topic/62446-mod_rewrite-or-some-other-method/#findComment-310907 Share on other sites More sharing options...
sKunKbad Posted July 30, 2007 Share Posted July 30, 2007 ModRewrite can be tricky. For instance on my server, I had to have: Options FollowSymLinks right above my rewriteEngine on for modrewrite to work. Quote Link to comment https://forums.phpfreaks.com/topic/62446-mod_rewrite-or-some-other-method/#findComment-310924 Share on other sites More sharing options...
wildteen88 Posted July 30, 2007 Share Posted July 30, 2007 Check your servers error log. There is a problem with your .htaccess. Make sured you host allows you use mod_rewrite or they have the mod_rewrite Apache module loaded Also you should use $_GET rather than $HTTP_GET_VARS. $HTTP_*_VARS has been replaced by $_* Also when you go run user.php dont actually go to user.php you just do this: mysite.com/user_name_here Apache will then call user.php?userid=user_name_here without showing the file being called in address bar. This is how mod_rewrite works. Quote Link to comment https://forums.phpfreaks.com/topic/62446-mod_rewrite-or-some-other-method/#findComment-310941 Share on other sites More sharing options...
ali_kiyani Posted July 30, 2007 Author Share Posted July 30, 2007 I tried Options FollowSymLinks but didn't work. I have asked my host to look into because like wildteen88 said it is possible that mod_rewrite is not allowed or there is some problem in it. Quote Link to comment https://forums.phpfreaks.com/topic/62446-mod_rewrite-or-some-other-method/#findComment-311135 Share on other sites More sharing options...
wildteen88 Posted July 30, 2007 Share Posted July 30, 2007 Oh... Hhold on... Sorry I had a few typos in my mod_rewrite code. Try this: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([a-z0-9]+) user.php?userid=$1 [NC,L] I didn't test what I posted last time. The above should now work. Quote Link to comment https://forums.phpfreaks.com/topic/62446-mod_rewrite-or-some-other-method/#findComment-311221 Share on other sites More sharing options...
ali_kiyani Posted July 31, 2007 Author Share Posted July 31, 2007 Cool...this one worked! thanks But there is one problem though In my user.php file I am printing $_GET["userid"] to see its value and this is happening 1. When I go to URL www.mywebsite.com/ali_kiyani then it prints home 2. When I go to URL www.mywebsite.com/ali_kiyani.php then it prints ali_kiyani I think that 'home' in first point is the base directory which it shouldn't be printing and rather it should print 'ali_kiyani' like in point 2 but with out having to write .php in the end. Quote Link to comment https://forums.phpfreaks.com/topic/62446-mod_rewrite-or-some-other-method/#findComment-311655 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.