Hi all i am creating small webapp with php where mydomain.com/profile.php?id=12345 this was users profile page ,and then with get method ,i fetch user data from database as below code $userid=$_GET['id']; $qry="select * from `users` where userid ='$userid'"; echo $qry; $result=mysql_query($qry); $userinfo = mysql_fetch_array($result); $u_name=$userinfo['name']; $u_userid=$userinfo['userid']; $u_gender=$userinfo['gender']; but i want my url like this mydomain.com/username without .php or anything can any one help me to fix this get method doesn't work here any other option?
Hi, you could use mod-rewrite for the pretty url. http://www.roscripts.com/Pretty_URLs_-_a_guide_to_URL_rewriting-168.html This may help you Thanks Djkanna
if i use mod_rewite to convert mydomin.com/profile.php?id=12345 mydomin.com/profile/balaji how can i use get method to fetch user information from database
RewriteRule ^profile/([a-z]+)$ profile.php?name=$1 Code (markup): $clean_name = preg_replace('/[^a-z]/', '', trim($_GET['name'])); $sql = "select * from users where name='{$clean_name}'"; PHP:
Get method work with only if domain look like this? mydomain.com?name=balaji $get['name'] if we don't use name variable in domain how get method will work?
Instead of using username in url its better to use session to pass the variables. $_SESSION["uname"]="yourusername"; PHP:
It works because the RewriteRule that I posted takes the username off the end of the URL and inserts it into the GET arguments list. Why not try it?
thanks @ SmallPotatoes: i tried its working but its working for all the file inside the folder!!!! please help me to fix this
I think you are setting yourself up for namespace conflicts. If you want http://mydomain.com/profile/abcdef to open someone's profile, then don't put anything else in http://mydomain.com/profile/ because sooner or later you will have someone whose user name is the same as something you put in there. Either move everything else out of /profile or make the profiles display under /user_profile or something like that.