timmah1 Posted December 13, 2006 Share Posted December 13, 2006 I have a photo hosting site, and when the user signs up, they get their own domain, kinda like myspaceWhat I want know is, when someone types in the url of a person (ie http://www.domainname.com/user), how would PHP know to pull information associated with that user? Link to comment https://forums.phpfreaks.com/topic/30545-url-question/ Share on other sites More sharing options...
joquius Posted December 13, 2006 Share Posted December 13, 2006 well all you need is to get the domain name from a http request, and match that with the database information. Lets says johnnysdomain is in the url requested of your host, you look that up in the database where you inputted the domain name originally.If you notice:[code]$host_name = explode (".", $_SERVER['HTTP_HOST']); // quite lazy[/code]$host_name[0] or $host_name[1] will get you the domain name and you just have to match that to the database (key 0 may be www, ftp, etc.) Link to comment https://forums.phpfreaks.com/topic/30545-url-question/#findComment-140605 Share on other sites More sharing options...
simcoweb Posted December 13, 2006 Share Posted December 13, 2006 Yup, the database query would pull the name from the url with a $_GET statement then use that info in a WHERE clause in the query. Link to comment https://forums.phpfreaks.com/topic/30545-url-question/#findComment-140611 Share on other sites More sharing options...
Caesar Posted December 13, 2006 Share Posted December 13, 2006 Best way...let Apache do it. mod_rewrite for the win! Link to comment https://forums.phpfreaks.com/topic/30545-url-question/#findComment-140612 Share on other sites More sharing options...
The Little Guy Posted December 13, 2006 Share Posted December 13, 2006 you need a .htaccess fileand in it you would place something like this:[code]Options +FollowSymlinksRewriteEngine onRewriteRule ^(.+)/$ /user_page.php?username=$1[/code]Then in your PHP file just search the database something like this:[code]<?php $sql = mysql_query("select * FROM users where username='{$_GET['username']}' LIMIT 1"); while($row = mysql_fetch_array($sql)){ echo$row['username']; echo$row['userid']; echo$row['filename']; }?>[/code]That is just an example of how to do it, but the .htaccess file is required, and for an .htaccess tutorial, go here: http://corz.org/serv/tricks/htaccess2.php -- its one I really like. Link to comment https://forums.phpfreaks.com/topic/30545-url-question/#findComment-140615 Share on other sites More sharing options...
timmah1 Posted December 13, 2006 Author Share Posted December 13, 2006 ok, this still confuses meWhen someone signs up, their username is their domain.If the url that somebody types in ishttp://www.domain.com/mysiteHow would the site now to pull all the information for the user 'mysite'? Link to comment https://forums.phpfreaks.com/topic/30545-url-question/#findComment-140629 Share on other sites More sharing options...
joquius Posted December 13, 2006 Share Posted December 13, 2006 $array = explode ("/", $_SERVER['HTTP_REQUEST']);$user = $array (count ($array) - 1); // extremely lazythis is if it's a "shared" domain, with a directory/page Link to comment https://forums.phpfreaks.com/topic/30545-url-question/#findComment-140633 Share on other sites More sharing options...
timmah1 Posted December 14, 2006 Author Share Posted December 14, 2006 ok, i'm a dumb ass.I didn't mean to say their own 'domain', the get their own 'directory', which is a alot differenthttp://www.domainname.com/directoryHow would I pull the username from just typing in the address the url?The username will always be the directory, in this example, the username is 'directory'I'm trying to understand this, but for some reason it's not sticking Link to comment https://forums.phpfreaks.com/topic/30545-url-question/#findComment-141149 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.