Forum Moderators: coopster

Message Too Old, No Replies

Dynamic URLs

         

wigwambam

9:20 pm on May 25, 2006 (gmt 0)

10+ Year Member



Quite hard to explain, here goes...

I have a site called (for example) www.whatever.com

I want people to create their own pages on www.whatever.com with their own names.

e.g.
www.whatever.com/fred
www.whatever.com/john
www.whatever.com/betty

The above is very easy to do if I create a directory for each user. I DO NOT want to do this. I anticipate 1,000's of users and do not want 1,000's of folders.

I know I can do:
www.whatever.com/index.php?user=fred
www.whatever.com/index.php?user=john
www.whatever.com/index.php?user=betty

But, being a fussy so and so, I don't like this.

Is there a way to use the first example without creating the directories?

Any ideas / suggestions appreciated.

alexorig

10:03 pm on May 25, 2006 (gmt 0)

10+ Year Member



Yes there totally is using either .htaccess file or the zeus mod_redirect functionality depending on how your server is set up. Under the apache server forum there are several strings which explain how to do this

wigwambam

10:13 pm on May 25, 2006 (gmt 0)

10+ Year Member



Thanks alexorig for your reply. You mentioned "Under the apache server forum there are several strings which explain how to do this" - is there a link?

Cheers.

jatar_k

10:15 pm on May 25, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



try the Apache Forum Library [webmasterworld.com]

there are a ton of threads on mod_rewrite

wigwambam

10:21 pm on May 25, 2006 (gmt 0)

10+ Year Member



Thanks a lot - I knew I would get the answer here. As a recent convert from asp to php its good to know that there are people willing to help.

Thanks again.

frozenpeas

11:37 pm on May 27, 2006 (gmt 0)

10+ Year Member



The files will probably have to be inside sub directories anyway as many hosting companies will not give permission to write to the root.
Number the directories by user_id so that many people with the same name can exist then rewrite the urls once the pages have been created.

eeek

8:02 pm on May 28, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Take a look at path_info

henry0

2:13 pm on May 29, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I use this and it works fine:

You could have a page template

Copy it within a given dir ex: member
Rename the copied page by using user’s name
Open and write to copied page for ex: $page_name=”fred.php”;
Add a field in DB with page URL www.whatever.com/member/fred.php
Show all or selected URLs, clicking on “fred.php” trigger a query: select from users_table where $page_name=’fred.php’

frozenpeas

8:36 pm on May 29, 2006 (gmt 0)

10+ Year Member



What if there are 2 people named Fred?
I think using a unique ID would be better.

henry0

9:59 pm on May 29, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Indeed you can use two identifiers
such as ID and page name
But if writing to the file (page) I like better using a rand() than ID.

frozenpeas

11:53 am on May 30, 2006 (gmt 0)

10+ Year Member



Interesting, I thought that Rand can never be truely random.
I prefer the autoincremental field as this never seems to duplicate.

henry0

12:05 pm on May 30, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try this one
<<<
<?php
// Our string will have 8 characters, but you can easy change
for($i = 0; $i < 8; $i++) {
// All the letters and numbers
$type[1] = "A¦B¦C¦D¦E¦F¦G¦H¦I¦J¦K¦L¦M¦N¦O¦P¦Q¦R¦S¦T¦U¦V¦X¦W¦Y¦Z";
$type[2] = "0¦1¦2¦3¦4¦5¦6¦7¦8¦9";

// Change for letter or number
$randType = rand(1, 2);

// Get an character alone
$type = explode("¦", $type[$randType]);
// Get the total size of characters
$max = count($type);

// Randonic character
$randChar = rand(0, $max);
$code .= $type[$randChar];
}

// Print the rand
echo "the rand generated was: ".$code;
?>

>>>
Plus you need to query for dup to take care of the dup eventuality.

I do not use ID because anyone could figure other ID above and below
although you may use a rewrite to clean the ID #.