| Home | Register | FAQ | Members List | Search | Today's Posts | Mark Forums Read |
|
|
#1 (permalink) |
|
knocking heads
Join Date: Jul 2003
Location: London, UK
Posts: 1,935
|
PHP - virtual directories
Hi, Just a quick overview before I get down to the nitty gritty. I am developing a website which is membership based - i.e people can register on the site. I want each member to have their own "page". For example, let's say user "tomjones" registers with the site, I want them to be able to go to www.mysite.com/tomjones and have it display their page. Obviously, the original way would be to do something like www.mysite.com/memberspage.php?id=tomjones It's messy, hard for the member to remember, and not good for search engine optimisation. I do not have root access on my host (i.e the ability to alter the Apache configuration) so that is not an option. I've been looking into htaccess modification but can't find anything that seems to match what I want to do. In addition, what happens if I have some REAL folders? eg. www.mysite.com/stats. I wouldnt want any scripts to think "stats" was a user page.. I would appreciate any help that you can give me, whether it be a link to a tutorial or giving me a bit of advice on this forum. Thanks in advance Scott |
|
|
|
|
|
#4 (permalink) |
|
knocking heads
Join Date: Jul 2003
Location: London, UK
Posts: 1,935
|
all the tutorials for mod_rewrite say that i have to have access to my appache httpd.config file - which as i mentioned before, i dont have unfortunately.. in addition, it seems that i would have to have something like www.mysite.com/file.php/variables/here but what i need is www.mysite.com/variablehere and then a script takes variablehere (which will be the username) and then grabs that info from the database etc etc |
|
|
|
#5 (permalink) |
|
Rough Creep Arse™
|
Take a look there.. you don't necessarily need to have .php anywhere. Also it might already be set up on your host. Drop them an email to ask if mod_rewrite has been set up, i'd be surprised if it's not. http://www.phpfreaks.com/tutorials/23/0.php |
|
|
|
#8 (permalink) |
|
knocking heads
Join Date: Jul 2003
Location: London, UK
Posts: 1,935
|
yup, its supported! on a side note, i got a good explanation that you lot may (or may not!) find useful: "Remember that PHP is a script parsing language. When people go to www.mysite.com/tomjones, PHP doesn't see the request at all. Apache receives the request, decides what to do with it and, if appropriate, it passes the script to PHP to be processed. What you want to do requires modifications to be made above PHP so that Apache recognizes the "folder" as a variable to feed to PHP. I have never done this, but I have a feeling Apache's mod_rewrite might be a good place to start. However, if you don't have any access at all to Apache setup, you are S.O.L. anyways." rebelo |
|
|
|
#9 (permalink) |
|
knocking heads
Join Date: Jul 2003
Location: London, UK
Posts: 1,935
|
ok, i need a bit more help! mod_rewrite is clearly the way to go, thanks so far i have the following rule in my .htaccess file Code:
if you go to http://developer.guavastudios.com/joebloggs/ you will see that it is working (it sets joebloggs as the id in members.php) however, if you go to http://developer.guavastudios.com/joebloggs a 404 error is shown - it needs the trailing slash so the rule knows to put joebloggs as the id.. however, i dont want people to have to put /joebloggs/ as people, on the whole, won't remember to put a trailing slash in the words of the beatles, "help, i need somebody!" |
|
|
|
#11 (permalink) |
|
knocking heads
Join Date: Jul 2003
Location: London, UK
Posts: 1,935
|
success...! Code:
i've had to settle with having the url be www.mydomain.com/~username but i think that will do nicely |
|
|
|
#12 (permalink) | |
|
volkswagen yellow & gold
Join Date: Apr 2003
Location: london, england.
Posts: 6,186
|
wouldn't do that if i were you. most people don't know what a tilde is, let alone how to describe what it is or where to find it on a keyboard. google just spat this out too: Quote:
|
|
|
|
|
#16 (permalink) |
|
knocking heads
Join Date: Jul 2003
Location: London, UK
Posts: 1,935
|
cheers smallbeer to be honest, i dont know what i "need" as i'm new to regular expresions and working with mod_rewrite (ive been browsing the net looking for solutions and just putting things together to see if they work) |
|
|
|
#17 (permalink) |
|
I Ain't Losing Any Sleep™
Join Date: Apr 2003
Posts: 5,235
|
I'm no expert either but you may want to think about how these usernames are going to be made up. just letters? alphanumeric? any other characters to be allowed? using wildcards can sometimes be dangerous as anything will be accepted. anyway. I think I have a better solution. Code:
it checks that teh request filename doesn't exist. These two lines check that the request filename doesn't exist. !-f - not a file !-d - not a directory |
|
|
|
#18 (permalink) |
|
knocking heads
Join Date: Jul 2003
Location: London, UK
Posts: 1,935
|
you sir, are truly the man although, there is one slight problem with that, if someone puts in www.mysite.com/test/ (note the trailing /) it wont work.. |
|
|
|
#20 (permalink) |
|
knocking heads
Join Date: Jul 2003
Location: London, UK
Posts: 1,935
|
nope.. if you go to www.mysite.com/test then the graphics etc all show fine, but if you go to /test/ it calls members.php but now the images folder isnt being called correctly, and the files in root directory no longer show.. |
|
![]() |