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!

Link to comment
Share on other sites

Hello kjetterman,

 

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

 

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:

 

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.

Edited by Andy123
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.