tags:

views:

233

answers:

4

I have been trying this for hours

<?php

if ($_SERVER['SERVER_NAME']=='http://www.testground.idghosting.com/idi' && $_SERVER['REQUEST_URI'] == 'our-production/') {

         echo '<div id="services">
<h1>Our services</h1>
<a href="<?php bloginfo(\'url\'); ?>" id="serv_productions" title="Our Productions"><span>Our Productions</span></a>
<a href="<?php bloginfo(\'url\'); ?>" id="serv_services" title="Production Services"><span>Production Services</span></a>
<a href="<?php bloginfo(\'url\'); ?>" id="serv_equipment" title="Equipment &amp; Facilities"><span>Equipment &amp; Facilities</span></a>
<a href="<?php bloginfo(\'url\'); ?>" id="serv_pr" title="PR &amp; Media"><span>PR &amp; Media</span></a>

</div>';
     } else {
         echo '<div> do not show</div>';
     } ;
 ?>

but no luck... a help would be very much appreciated..

+5  A: 

That's never going to match because $_SERVER['SERVER_NAME'] is just the domain name of the server, not the url itself.

Some of the items in the $_SERVER array that may be of use to you:

  • SERVER_NAME The full domain name of the server executing the script (eg myserver.foo.com)
  • REQUEST_URI The portion of the URL that comes after the server name, including the query string (if any)
  • SCRIPT_NAME The portion of the URL after the server name, excluding the query string.

One thing I like to do for handling code that gets executed for development and not on a live site is to create a define based on the hostname.

For example:

define('IS_LIVE', (strstr($_SERVER['SERVER_NAME'], 'mytestserver') ? true : false));

If I put that define somewhere that gets called for every page, then elsewhere in my code, I can do this:

if(!IS_LIVE) {
  //Do development-debugging stuff
}
Mark Biek
Thanks for the ups I didt the print_r($_SERVER); command and copied the server, request_uri but still not working
kwek-kwek
Are you trying to make it so the if statement only runs on www.testground.idghosting.com?
Mark Biek
A: 

Use

if(substr($_SERVER["REQUEST_URI"], 0, 4) == "/idi" //followed by your other code
Time Machine
that didn't work....
kwek-kwek
any other suggestions???
kwek-kwek
A: 

I have the solution....

<?php
//use body ID to whick page you want to dipaly a block
if (is_page(array('bodyid','bodyid', 'bodyid'))) { ;?>

<div id="services">
<h1>Our services</h1>
<a href="<?php bloginfo('url'); ?>" id="serv_productions" title="Our Productions"><span>Our Productions</span></a>
<a href="<?php bloginfo('url'); ?>" id="serv_services" title="Production Services"><span>Production Services</span></a>
<a href="<?php bloginfo('url'); ?>" id="serv_equipment" title="Equipment &amp; Facilities"><span>Equipment &amp; Facilities</span></a>
<a href="<?php bloginfo('url'); ?>" id="serv_pr" title="PR &amp; Media"><span>PR &amp; Media</span></a>

</div>
<?php } ?>
kwek-kwek
A: 

You also have an extra semi-colon:

</div>';
  } else {
      echo '<div> do not show</div>';
  } ; 
//  ^ remove this semi-colon
John Rasch
I dont think this will give a syntax error in php. Its just an empty statement.
Toby Allen