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
https://forums.phpfreaks.com/topic/92523-need-the-right-direction/
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?

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?

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.