Jump to content

Logic Error -- Trying To Get Phone Number To Show Up Depending On Url


kjetterman

Recommended Posts

Hi everyone!

 

So.. I am in the process of writing a script that will put a phone number on the site depending on the subdomain location. Here is the code:

 

<?
   $testPhone = "800.555.1212";
   $michiganPhone = "800.783.1623";
   $ohioPhone = "800.282.5106";
   $pennPhone = "800.233.8200";
   $floridaPhone = "800.292.9111";
   $texasPhone = "800.633.1122";

   $host = $_SERVER['HTTP_HOST'];

   if ($host == 'diocesan.com./testsite/publishing.php')
   {
       echo '$testPhone';
   }
   elseif ($host == 'diocesan.com/michigan/')
   {
       echo $michiganPhone;
   }
   elseif ($host == 'diocesan.com/ohio/')
   {
       echo $ohioPhone;
   }
   elseif ($host == 'diocesan.com/pennsylvania/')
   {
       echo $pennPhone;
   }
   elseif ($host == 'diocesan.com/florida/')
   {
       echo $floridaPhone;
   }
   elseif ($host == 'trinitypublications.com/texas/')
   {
       echo $texasPhone;
   }


?>

 

The syntax is correct but the logic is not because the number isn't showing up. How can I go about this the right way? What am I not considering here?

 

Thank you so very much for any help / advice you may be able to give! I really appreicate it!

Hello kjetterman,

 

In the manual for the $_SERVER superglobal, the following is written about SERVER_NAME:

 

  Quote
The name of the server host under which the current script is executing. If the script is running on a virtual host, this will be the value defined for that virtual host.

 

Therefore, you are only accessing the name of the host (probably your domain) and not the relative path after the domain name. As a result, none of your logical statements evaluate to true.

 

Taking a look at REQUEST_URI, the following is written:

 

  Quote
The URI which was given in order to access this page; for instance, '/index.html'.

 

Try doing like this:

 

$address = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];

 

You will probably want to print the contents of the variable so that you can better understand what actually happens.

 

I have a tendency of always forgetting these array keys and how it all works together, so please correct me if I am wrong.

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.