Banner that changes depending on how a site is accessed?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Bit343
Forum Newbie
Posts: 3
Joined: Tue Jun 08, 2004 10:53 pm

Banner that changes depending on how a site is accessed?

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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]()
Bit343
Forum Newbie
Posts: 3
Joined: Tue Jun 08, 2004 10:53 pm

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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
?>
Bit343
Forum Newbie
Posts: 3
Joined: Tue Jun 08, 2004 10:53 pm

Post by Bit343 »

Using the first one,

Parse error: parse error in /banner.php on line 8
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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...
Post Reply