Page 1 of 1
Banner that changes depending on how a site is accessed?
Posted: Tue Jun 08, 2004 10:53 pm
by Bit343
I'm working on a webpage, and I plan to offer content for multiple users on the same site. What I plan to do is have
http://www.mysite.com which will display an index of all users, and also have user.mysite.com which will direct to the users content. I want the banner to vary depending on which way you access the site (or what content you are accessing), so it can display "My Site" or "User's site"
Thank you to anyone that can help.
Posted: Tue Jun 08, 2004 10:56 pm
by feyd
if you are using true subdomains, then you can use $_SERVER['HTTP_HOST']. If the subdomain is a redirector, you'll need to use something like [php_man]parse_url[/php_man]()
Posted: Tue Jun 08, 2004 11:06 pm
by Bit343
I hate to sound like a complete novice, but I am... could you spell it out for me? I really need an example of what the complete script would look like.
Posted: Tue Jun 08, 2004 11:43 pm
by feyd
for real subdomains:
Code: Select all
<?php
$site = preg_replace("|^([^\.]+?).*?$|","\\1",$_SERVER['HTTP_HOST']); // get everything before the first dot
switch($site)
{
case 'jimmy':
// 'jimmy' specific banner(s) and content settings
break;
case 'jane':
// 'jane' specific banners(s) and content settings
break;
default:
// if the user isn't known or if it's http://www.mysite.com
// do generic banner(s) and content settings
break;
}
// all other code down here
?>
for redirector based:
Code: Select all
<?php
$site = explode('/',$_SERVER['REQUEST_URI']);
if(sizeof($site) >= 1)
$site = $site[1];
else
$site = '';
switch($site)
{
case 'jimmy':
// 'jimmy' specific banner(s) and content settings
break;
case 'jane':
// 'jane' specific banners(s) and content settings
break;
default:
// if the user isn't known or if it's http://www.mysite.com
// do generic banner(s) and content settings
break;
}
// all other code down here
?>
Posted: Wed Jun 09, 2004 12:36 am
by Bit343
Using the first one,
Parse error: parse error in /banner.php on line 8
Posted: Wed Jun 09, 2004 2:16 am
by feyd
outside a logic error in my regex it worked perfectly fine for me..
Code: Select all
preg_match("|^([^.]+?)\.|",$_SERVER['HTTP_HOST'],$site); // get everything before the first dot
$site = $site[1];
post your code if you continue to have an error...