Jump to content

[SOLVED] Wondering if I can do this


toothmkr57

Recommended Posts

<?php

$domain = $_SERVER['SERVER_NAME'];
echo $domain;

?>

 

Run that code in the page on its own and tell me the result please.

 

pmcsravenstone.com

 

 

 

You are sure that wasn't www.pmcsravenstone.com as SERVER_NAME should include the www. also are you including the header_image.php file before the header.php file?

Scrap that then...

 


<?php

$domain = $_SERVER['SERVER_NAME'];

echo 'Domain: ' . $domain . '<br><br>';

$imgUrl = "http://www.pmcsravenstone.com/media/";
switch ($domain)
{
case "webdesign.pmcsravenstone.com":
  $imgUrl .= "web.png";
  break;
case "dental.pmcsravenstone.com":
  $imgUrl .= "dental.png";
  break;
case "family.pmcsravenstone.com":
  $imgUrl .= "family.png";
  break;
case "fun.pmcsravenstone.com":
  $imgUrl .= "fun.png";
  break;
default:
  $imgUrl .= "bridge.jpg";
  break;
}

echo 'Url: ' . $imgUrl . '<br>';

?>

 

Change header_image.php to that and we can find the problem from there...

Ok, so here is the correct code Andy so gratefully fixed up!

<?php

$domain = $_SERVER['SERVER_NAME'];

$parts = explode('.', $domain);

if ($parts[0] == "www"){

$parts = array_slice($parts, 1);

$url   = implode('.', $parts);

}else{

$url = $domain;

}



$imgUrl = "http://www.pmcsravenstone.com/media/";
switch ($url)
{
case "webdesign.pmcsravenstone.com":
  $imgUrl .= "web.png";
  break;
case "dental.pmcsravenstone.com":
  $imgUrl .= "dental.png";
  break;
case "family.pmcsravenstone.com":
  $imgUrl .= "family.png";
  break;
case "fun.pmcsravenstone.com":
  $imgUrl .= "fun.png";
  break;
default:
  $imgUrl .= "bridge.jpg";
  break;
}


?>

 

 

Ok, so here is the correct code Andy so gratefully fixed up!

<?php

$domain = $_SERVER['SERVER_NAME'];

$parts = explode('.', $domain);  /* splits the string into an array seperated
by the dots ie $parts[0] => "www", $parts[1] => "webdesign", etc...*/

if ($parts[0] == "www"){ // check if the first value of parts is "www"

$parts = array_slice($parts, 1); // if it is remove the first value

$url   = implode('.', $parts); 

/* 'implode' the array values back into a string and add
the dots between each value back and set the string to the $url variable..*/

}else{

   $url = $domain;  // else $domain is ok to use, set it to $url var

}



$imgUrl = "http://www.pmcsravenstone.com/media/";
switch ($url) // change the switch case to $url instead of $domain.
{
// the rest all works the same.

case "webdesign.pmcsravenstone.com":
  $imgUrl .= "web.png";
  break;
case "dental.pmcsravenstone.com":
  $imgUrl .= "dental.png";
  break;
case "family.pmcsravenstone.com":
  $imgUrl .= "family.png";
  break;
case "fun.pmcsravenstone.com":
  $imgUrl .= "fun.png";
  break;
default:
  $imgUrl .= "bridge.jpg";
  break;
}


?>

 

 

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.