tags:

views:

1127

answers:

8

I tried doing this but then it is not working

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

to see the sample click here see the block where it says Our services in the bottom I don't want it to be shown on ths page but visible to all other pages....

+10  A: 

Always indent your code — it's simplier to see errors

 <?php
     if ($url == "http://www.sample.com/test.php") {
         echo "<div>whatever</div>";
     } else {
         echo "<div> do not show</div>";
     };
 ?>

Note the placement of curly brackets.

Kuroki Kaze
+1 for the advice of keep the code indented
DaNieL
I'm being pedantic here i think, but his syntax was fine except that he was missing the word echo directly after 'else'. But yes syntax was weird, but legal I think?
David Archer
My IDE says syntax is not legal. You cannot place string after opening curly brace.
Kuroki Kaze
A: 
<?php
    if($url == "http://www.sample.com/test.php")
    {
        echo "<div>whatever</div>";
    }
    else
    {
        echo "<div> do not show</div>";
    }
?>

Your syntax was just a little wrong.

+1  A: 
<?php

if ($_SERVER['SERVER_NAME']=='www.sample.com' && $_SERVER['REQUEST_URI'] == '/test.php') {
  echo 'blah';
} else {
  echo 'asdf';
}

?>
scompt.com
+3  A: 

Or you could use the ternary operator. All on one line if you like - I broke it up to avoid the evil scrollbars.

echo ($url == "http://www.sample.com/test.php") 
       ? "<div>Whatever</div>" 
       : "";
Jonathan Sampson
"I broke it up to avoid the evil scrollbars" - obvious reason to *not* do it in one-liner :)
Kuroki Kaze
A: 

There does not currently seem to be a direct way. What you’ll have to do is to reconstruct the URL by combining entries from the $_SERVER array. You can check the results of the phpinfo() to see what entries you need.

Synetech inc.
A: 

At a higher level, have you considered changing your approach for getting this onto the pages where you want it? You could put the section within the then part of your code into a separate file which you include into those files in which you want it to appear.

PTBNL
+2  A: 

You’re using the wrong values.

// REQUEST_URI is the requested URI path plus the requested URI query, so let’s strip the latter
$_SERVER['REQUEST_URI_PATH'] = preg_replace('/\?.*/', '', $_SERVER['REQUEST_URI']);
// HTTP_HOST may not be set if the request didn’t contain the Host header field (just HTTP/1.0)
if (isset($_SERVER['HTTP_HOST']) && $_SERVER['HTTP_HOST']=='www.testground.idghosting.com' && $_SERVER['REQUEST_URI_PATH'] == '/idi/our-production/') {
    // host is "www.testground.idghosting.com" and requested URI path is "/idi/our-production/"
}

See the manual for what values the $_SERVER contains.

Gumbo
A: 

The problem here is that in the echo string, you open a php tag, but that is already php code, so you don't have to open that tag. You'd have to one one if you were in HTML code.

Petruza