foevah Posted June 9, 2009 Share Posted June 9, 2009 Hi I am not sure how to explain this but let me type it in steps to help you understand what I want to achieve: if website = test area domain http://dev-site.com then echo { no google analytics } or else { if website = live domain echo http://live-site.com then echo { google analytics } if only code what that easy! hehe.. If anyone understands the above then please can someone show me how to do this? I think this will be useful and I want to know if it is possible? Quote Link to comment https://forums.phpfreaks.com/topic/161499-if-dev-site-then-echo-code-but-if-live-site-then-echo-code-help/ Share on other sites More sharing options...
trq Posted June 9, 2009 Share Posted June 9, 2009 if only code what that easy! It is when you know what variables are available. if ($_SERVER['SERVER_NAME'] == 'http://dev-site.com') { echo "no google analytics"; else if ($_SERVER['SERVER_NAME'] == 'http://live-site.com') { echo "google analytics"; } Quote Link to comment https://forums.phpfreaks.com/topic/161499-if-dev-site-then-echo-code-but-if-live-site-then-echo-code-help/#findComment-852248 Share on other sites More sharing options...
scvinodkumar Posted June 9, 2009 Share Posted June 9, 2009 or simply, if ($_SERVER['SERVER_NAME'] == 'http://live-site.com') { echo "google analytics"; } Quote Link to comment https://forums.phpfreaks.com/topic/161499-if-dev-site-then-echo-code-but-if-live-site-then-echo-code-help/#findComment-852249 Share on other sites More sharing options...
foevah Posted June 9, 2009 Author Share Posted June 9, 2009 does that cover all pages on that domain like http://live-site.com/contact.php ? Quote Link to comment https://forums.phpfreaks.com/topic/161499-if-dev-site-then-echo-code-but-if-live-site-then-echo-code-help/#findComment-852264 Share on other sites More sharing options...
Garethp Posted June 9, 2009 Share Posted June 9, 2009 Yes. Try the code before asking if it works Quote Link to comment https://forums.phpfreaks.com/topic/161499-if-dev-site-then-echo-code-but-if-live-site-then-echo-code-help/#findComment-852268 Share on other sites More sharing options...
foevah Posted June 9, 2009 Author Share Posted June 9, 2009 i am getting this error: Parse error: syntax error, unexpected T_ELSE in C:\websites\devsite\footer.php on line 26 i am using thorpe's example: if ($_SERVER['SERVER_NAME'] == 'http://dev.local/') { echo "no google analytics"; else if ($_SERVER['SERVER_NAME'] == 'http://live-site.com/') { echo "<script type="text/javascript" src="js/ga.js"></script>"; } Quote Link to comment https://forums.phpfreaks.com/topic/161499-if-dev-site-then-echo-code-but-if-live-site-then-echo-code-help/#findComment-852269 Share on other sites More sharing options...
Garethp Posted June 9, 2009 Share Posted June 9, 2009 You missed an } after your if Quote Link to comment https://forums.phpfreaks.com/topic/161499-if-dev-site-then-echo-code-but-if-live-site-then-echo-code-help/#findComment-852270 Share on other sites More sharing options...
foevah Posted June 9, 2009 Author Share Posted June 9, 2009 ok I found a missing curly bracket but the ga.js doesnt show in the source? if ($_SERVER['SERVER_NAME'] == 'http://dev.local/') { echo "no google analytics"; } else if ($_SERVER['SERVER_NAME'] == 'http://www.live-site.com') { echo "<script type='text/javascript' src='js/ga.js'></script>"; } Quote Link to comment https://forums.phpfreaks.com/topic/161499-if-dev-site-then-echo-code-but-if-live-site-then-echo-code-help/#findComment-852272 Share on other sites More sharing options...
Garethp Posted June 9, 2009 Share Posted June 9, 2009 What's the output of this code? if ($_SERVER['SERVER_NAME'] == 'http://dev.local/') { echo "no google analytics"; } else if ($_SERVER['SERVER_NAME'] == 'http://www.live-site.com') { echo "<script type='text/javascript' src='js/ga.js'></script>"; } else { echo $__SERVER['SERVER_NAME']; } Quote Link to comment https://forums.phpfreaks.com/topic/161499-if-dev-site-then-echo-code-but-if-live-site-then-echo-code-help/#findComment-852274 Share on other sites More sharing options...
foevah Posted June 9, 2009 Author Share Posted June 9, 2009 still nothing? does the live-site.com have to be on a live server because i am still testing it locally.. This is how mine looks: if ($_SERVER['SERVER_NAME'] == 'http://dev.local/') { echo "no google analytics"; } else if ($_SERVER['SERVER_NAME'] == 'http://testsite.local/') { echo "<script type='text/javascript' src='js/ga.js'></script>"; } else { echo $__SERVER['SERVER_NAME']; } Quote Link to comment https://forums.phpfreaks.com/topic/161499-if-dev-site-then-echo-code-but-if-live-site-then-echo-code-help/#findComment-852279 Share on other sites More sharing options...
Garethp Posted June 9, 2009 Share Posted June 9, 2009 I'm not entirely sure, but unless your using http://dev.local/ it should be outputting something Quote Link to comment https://forums.phpfreaks.com/topic/161499-if-dev-site-then-echo-code-but-if-live-site-then-echo-code-help/#findComment-852283 Share on other sites More sharing options...
foevah Posted June 9, 2009 Author Share Posted June 9, 2009 ya I am using dev.local.. I have put dev.local in both if statements and still nothing ?? if ($_SERVER['SERVER_NAME'] == 'http://dev.local/') { echo "no google analytics"; } else if ($_SERVER['SERVER_NAME'] == 'http://dev.local/') { echo "<script type='text/javascript' src='js/ga.js'></script>"; } else { echo $__SERVER['SERVER_NAME']; } Quote Link to comment https://forums.phpfreaks.com/topic/161499-if-dev-site-then-echo-code-but-if-live-site-then-echo-code-help/#findComment-852289 Share on other sites More sharing options...
scvinodkumar Posted June 9, 2009 Share Posted June 9, 2009 ok can you tell what will be output for this line, echo $__SERVER['SERVER_NAME']; just add this line within the php tags and run the file Quote Link to comment https://forums.phpfreaks.com/topic/161499-if-dev-site-then-echo-code-but-if-live-site-then-echo-code-help/#findComment-852301 Share on other sites More sharing options...
thebadbad Posted June 9, 2009 Share Posted June 9, 2009 Yeah, show us your output of <?php echo $_SERVER['SERVER_NAME']; ?> Garethp's code had two underscores in the variable name. Quote Link to comment https://forums.phpfreaks.com/topic/161499-if-dev-site-then-echo-code-but-if-live-site-then-echo-code-help/#findComment-852341 Share on other sites More sharing options...
foevah Posted June 9, 2009 Author Share Posted June 9, 2009 this is wrong: echo $__SERVER['SERVER_NAME']; it is: echo $_SERVER['SERVER_NAME']; the result is: dev.local Quote Link to comment https://forums.phpfreaks.com/topic/161499-if-dev-site-then-echo-code-but-if-live-site-then-echo-code-help/#findComment-852343 Share on other sites More sharing options...
scvinodkumar Posted June 9, 2009 Share Posted June 9, 2009 thanks, then use this code and check it if ($_SERVER['SERVER_NAME'] == 'dev.local') { echo "no google analytics"; } else if ($_SERVER['SERVER_NAME'] == 'testsite.local') { echo "<script type='text/javascript' src='js/ga.js'></script>"; } else { echo $__SERVER['SERVER_NAME']; } Quote Link to comment https://forums.phpfreaks.com/topic/161499-if-dev-site-then-echo-code-but-if-live-site-then-echo-code-help/#findComment-852346 Share on other sites More sharing options...
thebadbad Posted June 9, 2009 Share Posted June 9, 2009 Okay, then the code should look like this: <?php if ($_SERVER['SERVER_NAME'] == 'dev.local') { echo 'no google analytics'; } else if ($_SERVER['SERVER_NAME'] == 'testsite.local') { echo '<script type="text/javascript" src="js/ga.js"></script>'; } ?> And scvinodkumar, it should still be $_SERVER, not $__SERVER Quote Link to comment https://forums.phpfreaks.com/topic/161499-if-dev-site-then-echo-code-but-if-live-site-then-echo-code-help/#findComment-852348 Share on other sites More sharing options...
foevah Posted June 9, 2009 Author Share Posted June 9, 2009 ah cool thebadbad! thanks everyone for helping me.. does anyone else here use this technique? It only struck me today that I should try and do something like this because it is irritating deleting and adding this kind of stuff. Another situation where I will try and use this is for the meta data noindex nofollow. It is always a pain switching between nofollow and follow!! Quote Link to comment https://forums.phpfreaks.com/topic/161499-if-dev-site-then-echo-code-but-if-live-site-then-echo-code-help/#findComment-852359 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.