Jump to content

Need the right direction


a1amattyj

Recommended Posts

hello,

 

im currently coding a multi-forum hosting script. (Hosts multiple forums from one set of files but each forum has its own database)

 

the basics of it works. i want each new forum to have its own subdomain - e.g forumanme.domain.com not domain.com/forum/forumname/index.php

 

wildcard dns will be used, just have no idea how i can make this work. any links or examples?

 

thanks

Link to comment
Share on other sites

You can use mod_rewrite to redirect all requests through a single index.php.  You can use the same rewrite rule to append the subdomain as a $_GET variable.

RewriteRule ^http://([^.]+).domain.com/ /index.php?sub=$1

 

Then in index.php:

  if(isset($_GET['sub'])){
    mysql_connect('localhost', 'user', 'pass');
    mysql_select_db($_GET['sub']);
    include('forum.php');
  }else{
    include('main_site.php');
  }

 

Lacking data validation and a slew of other features, but does that help?

Link to comment
Share on other sites

You can use mod_rewrite to redirect all requests through a single index.php.  You can use the same rewrite rule to append the subdomain as a $_GET variable.

RewriteRule ^http://([^.]+).domain.com/ /index.php?sub=$1

 

Then in index.php:

  if(isset($_GET['sub'])){
    mysql_connect('localhost', 'user', 'pass');
    mysql_select_db($_GET['sub']);
    include('forum.php');
  }else{
    include('main_site.php');
  }

 

Lacking data validation and a slew of other features, but does that help?

 

Will i need to place the same kind of code in search.php admin.php etc?

Link to comment
Share on other sites

No.  That's the point.  You use mod_rewrite to send every page request through index.php.  index.php performs the steps necessary for all of your pages, such as establishing database connections.  Then index.php includes the proper file to display, such as search.php, admin.php, forums.php, etc.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.