Jump to content

if dev site then echo code but if live site then echo code ?!!? help


foevah

Recommended Posts

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?

 

 

Link to comment
Share on other sites

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";
}

Link to comment
Share on other sites

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>";

}

 

 

 

Link to comment
Share on other sites

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'];
}

Link to comment
Share on other sites

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'];

}

Link to comment
Share on other sites

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'];
}

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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!!

 

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.