best approach to build dynamic website?

malina

New Member
First of all Id like to say hi! since I am new to this forum.

I'd like to get some recommendations/suggestion on best practices when building a dynamic website.

In general I am developing a website where users can create their accounts. As soon as they activate it they can create their simple websites as user.domain.com. This is done using a dns wildcard plus some simple mod_rewrite redirections.

To be more specific when a person visits user's site - user.domain.com - he or she is redirected to the site root - domain.com - where the index.php file catches the "user" part and displays user specific content (based on the "user" part) from a database. I have already been told that some caching have to be involved in the process of delivering the content to the user's browser.

Users will have the ability to edit their sites (content in the database) and it's looks as well. The "content" part stored in the db is simply plain text and links to media files stored on the server, but there will be some serious css formatting and jquery visual effects.

My question is:
Is there any more sophisticated/faster and "valid" approach to resolve displaying user's pages to the audience?
What would be the best way to handle css in this case? Storing css values in the database, using user specific css files?
Users' sites will be generated from some default php template file which will be customized be modyfing css values and attributes.

If You could suggest some online tutorials/ articles on this matter I would be grateful, since I don't know where to look for such an abstract topics. I could also use any tips and comments.

Chris
 

Geodun1

New Member
Alright, I think I get the idea behind what you're wanting to do. You've got a good idea for how you're going to do this, but I'm curious how well it will perform under heavy use (300+ user sites, 5000+ visits a day sort of heavy use) when it comes to load times. You gotta remember, if things are slow, people will find an faster, easier method.

Basically, you should write out how you're going to structure the main page, I'll give you an example (VERY general, but an example) of how I would do it:

Layout of the Page

  1. On index load, connect to database, and check sessions/cookies to see if user is logged in.
  2. If logged in, display the users page relative to user.domain.com/index.html (load the html off that page).
  3. If not logged in, offer log in form next to a sign up form. This allows users to access their sites quickly and efficiently and new users to easily be able to sign up. Include pages that only display to non-logged in users so that new users can get information.

To handle the CSS you can do it in one of two ways, I'll describe both below:

  1. Store ALL css files in a single folder under the root for domain.com by usernamer, then call upon it when the page loads, relative to the username chosen.
  2. Store the css in the user.domain.com and simply link to it in the file like"<link rel="stylesheet" type="text/css" href="user.domain.com/cssfile.css" />".

I personally would go with the first option, but I think the second option might load faster. It's a matter of trial and error there. All in all, I don't know how well this entire system will perform, but I'd be interested in seeing.

In order to do all of this, you'll need basic knowledge of php (nothing TOO advanced here). The hardest part is making the login system :) I'm not familiar with how you're gonna register the subdomain, so you'll have to research that yourself.

Your database is going to be holding the following information most likely:

User Info
Site URLs
Form Info (This applies to the actual editing of the site, which will involve storing information while editing, possibly)

There's probably more, but you get where this is heading. If you have any questions, I'll be happy to answer :)
 

malina

New Member
Thank You very much for the answer Geodun1.

It is my first attempt to build a website that is going to generate so much traffic (hopefully) so yes - i'm also curious about the way it's going to use hosting resources - that is why it has to be designed in the best available way.

There will be no physical subdomains - only wildcard redirection. Database queries amount will be minimized to reduce processing time and I would go for the first way to link the css files, as the whole templates and looks issue is very important - i think it gives me more space to design various templates with different css styling.

As for my php knowledge I consider myself rather as an webdesigner than php programmer. The login/registration system that includes form validation and some ajax username availability etc. already exists on my localhost.

Now my thing is - as there will be no physical subdomains - should I:

1. use some user dedicated files - when user registers create "username" directory and copy some default php files into his user dir, then when he logs in redirect to his files, or

2. only use the root index.php to decide wheter he is logged in or not and if he is not this one big index.php file would be responsible for rendering the contents using database data and some user specific files

Which way would You go?

Hopefully this website is going to start in a month or so. We are planning to use a hosting service for about a year or two (depends on traffic/popularity) and then go for a dedicated server.

Additional question:
Is the algorithm below most efficient?

A. userA enters "www.domain.com" in the address bar -> check IF the subdomain is set (this includes dealing with the "www") -> IF NOT show him the main website with ads etc. let him see it, register, or login -> IF he logs in redirect to "userA.domain.com" with some kind of $_SESSION variable indicating he is logged in -> show him admin controls

B. user enters "userA.domain.com" in the address bar -> show him userA's content; if $_SESSION variable is not set -> he does not see any administration tools/links
 
Last edited:

Geodun1

New Member
Yeah, you got it on the processes. It's also worth accounting for a check to see if they check "Stay logged in." so remember that one.

As for which method to use, I would go with option one (User Directory). As for the domain questions, someone else will have to answer that, I'm not very experienced in domain usage or anything of that ilk. One of those things I've never needed ;)

Going hosted for the first year or two should be fine, but if things start slowing down and your traffic is on a positive trend, then you should consider a dedicated server. If it's slow with only 20-30 users, then there's an effieciency problem ;)
 

muckle.martin

New Member
If you have your own servers, you should consider using memcached to deliver frequently used content, you can cache user css in memcache.
 
Top