Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-05-2005, 03:18 PM   PM User | #1
:mo:
New Coder

 
Join Date: Jun 2005
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
:mo: is an unknown quantity at this point
Exclamation PHP redirect script PLZ HELP ME

Hello, i've recently bought a hosting package that allows me to point unlimited domains to my site. I would like different pages to display for each domain, but I get the same site.

Could anyone PLEASE design a script that will detect what domain is in the address bar and redirect to the corresponding folder

thx
:mo: is offline   Reply With Quote
Old 06-05-2005, 03:24 PM   PM User | #2
SeeIT Solutions
Regular Coder

 
Join Date: May 2005
Posts: 563
Thanks: 0
Thanked 3 Times in 3 Posts
SeeIT Solutions is on a distinguished road
If the hosting has cPanel included there is a redirects section that allows you to do this easily.
__________________
Design Portfolio
SeeIT Solutions is offline   Reply With Quote
Old 06-05-2005, 03:30 PM   PM User | #3
delinear
Regular Coder

 
Join Date: Feb 2005
Location: West Midlands, UK
Posts: 623
Thanks: 0
Thanked 0 Times in 0 Posts
delinear is an unknown quantity at this point
I think you can detect this through $_SERVER['SERVER_NAME'] or $_SERVER['HTTP_HOST']
__________________
~ Bazzy
delinear is offline   Reply With Quote
Old 06-05-2005, 03:39 PM   PM User | #4
:mo:
New Coder

 
Join Date: Jun 2005
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
:mo: is an unknown quantity at this point
Quote:
Originally Posted by SeeIT Solutions
If the hosting has cPanel included there is a redirects section that allows you to do this easily.


it doesnt unfortunately



thx 4 ur help anyway
:mo: is offline   Reply With Quote
Old 06-05-2005, 03:44 PM   PM User | #5
:mo:
New Coder

 
Join Date: Jun 2005
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
:mo: is an unknown quantity at this point
Quote:
Originally Posted by delinear
I think you can detect this through $_SERVER['SERVER_NAME'] or $_SERVER['HTTP_HOST']

thx, but i'm not very good with php

PHP Code:
if ($_SERVER['HTTP_HOST'] == "www.mydomain.com")
{
//then what
}


// i suppose ill have lots of elses underneath for al my domains 
3 Questions

1.)Could somebody do it for me? please
2.)If not, is that right?
3.)How do I do the redirect bit?
:mo: is offline   Reply With Quote
Old 06-05-2005, 03:52 PM   PM User | #6
delinear
Regular Coder

 
Join Date: Feb 2005
Location: West Midlands, UK
Posts: 623
Thanks: 0
Thanked 0 Times in 0 Posts
delinear is an unknown quantity at this point
If you just want to do a very simple redirect from index.php in the root to an index file in a sub directory (which I think will be the best option if you're still learning php) then you could do something like this:

PHP Code:
if(strpos($_SERVER['HTTP_HOST'], 'domain1.com')) {

    
header('Location: directory1/index.php');

} elseif(
strpos($_SERVER['HTTP_HOST'], 'domain2.com')) {

    
header('Location: directory2/index.php');
    

Although I'm sure there is a better solution using Apache to determine the domain and automatically show the correct sub directory, but I wouldn't know enough about Apache to be much help there.
__________________
~ Bazzy
delinear is offline   Reply With Quote
Old 06-05-2005, 03:54 PM   PM User | #7
:mo:
New Coder

 
Join Date: Jun 2005
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
:mo: is an unknown quantity at this point
thx


um.........will that work when there is www. or http:// in front?
:mo: is offline   Reply With Quote
Old 06-05-2005, 04:00 PM   PM User | #8
delinear
Regular Coder

 
Join Date: Feb 2005
Location: West Midlands, UK
Posts: 623
Thanks: 0
Thanked 0 Times in 0 Posts
delinear is an unknown quantity at this point
It should do, strpos() will determine if the domain appears anywhere within the $_SERVER['HTTP_HOST'] variable, so by leaving off the http and www parts you will catch anyone who arrives at the page without typing those parts too (hopefully!).
__________________
~ Bazzy
delinear is offline   Reply With Quote
Old 06-05-2005, 04:04 PM   PM User | #9
:mo:
New Coder

 
Join Date: Jun 2005
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
:mo: is an unknown quantity at this point
Quote:
Originally Posted by delinear
It should do, strpos() will determine if the domain appears anywhere within the $_SERVER['HTTP_HOST'] variable, so by leaving off the http and www parts you will catch anyone who arrives at the page without typing those parts too (hopefully!).
i havent had any probs yet


thx again
:mo: is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:17 AM.


Advertisement
Log in to turn off these ads.