kjetterman Posted December 21, 2012 Share Posted December 21, 2012 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! Quote Link to comment https://forums.phpfreaks.com/topic/272254-logic-error-trying-to-get-phone-number-to-show-up-depending-on-url/ Share on other sites More sharing options...
Andy123 Posted December 21, 2012 Share Posted December 21, 2012 (edited) 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 December 21, 2012 by Andy123 Quote Link to comment https://forums.phpfreaks.com/topic/272254-logic-error-trying-to-get-phone-number-to-show-up-depending-on-url/#findComment-1400777 Share on other sites More sharing options...
kjetterman Posted December 26, 2012 Author Share Posted December 26, 2012 Thank you, Andy! That was the missing link! It makes sense too! Quote Link to comment https://forums.phpfreaks.com/topic/272254-logic-error-trying-to-get-phone-number-to-show-up-depending-on-url/#findComment-1401323 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.