0

I want to show a DIV ONLY when on /../mahjong.php. So even if I go to /../mahjong.php?layout it should hide the div (since it's not the same url)

I have tried the following:

// We're NOT on the home page
if (strpos($_SERVER['REQUEST_URI'], "/games/mahjong/mahjong.php") >= 0) {
  $style = "display: none";
}
else {
  $style = "display: inline";
}

And my div ofcourse:

<div class="menu" id="menu" style="<?php echo $style; ?>">

But if I go to /games/mahjong/mahjong.php?layout it doesn't change the style. I've echoed:

echo $_SERVER['REQUEST_URI'];

and it changes to /games/mahjong/mahjong.php?layout, so why isn't the style set to inline?

 if (strpos($_SERVER['REQUEST_URI'], "/games/mahjong/mahjong.php") === false) {

Didn't work either. (this wil show the div and never hide it) What am I missing?

Many thanks,

Maurice

1
  • You might want to stick this conditional statement directly into your template file and only show the div when the case is true, because there's no reason to print HTML that isn't displaying. Commented Jun 15, 2011 at 17:25

4 Answers 4

1

Check if the $_GET array has been populated or not:

<?php if (empty($_GET)): ?>
<div>
...
</div>
<?php endif; ?>

Should be sufficient if you're not manually adding to the $_GET array, which would be very silly.

Sign up to request clarification or add additional context in comments.

3 Comments

Does $_GET contain the same info that is populated in $_SERVER['PATH_INFO']?
No, but it contains whatever's in the query string if present.
What if the URL is /foo/bar.php/more/info?var1=val1&var2=val2
0

Change your condition to:

strrpos($_SERVER['REQUEST_URI'], '/games/mahjong/mahjong.php') === strlen($_SERVER['REQUEST_URI']) - strlen('/games/mahjong/mahjong.php')

This will make sure the request uri ends with that string.

Comments

0

strpos(); only search for that string, and in both cases, string is found strpos(); isn'T exact search !

// We're NOT on the home page
if (strpos($_SERVER['REQUEST_URI'], "/games/mahjong/mahjong.php?layout") >= 0) {
  $style = "display: inline";
}
else {
  $style = "display: none";
}

or you can use

// We're NOT on the home page
if (isset($_GET['layout'])) {
  $style = "display: inline";
}
else {
  $style = "display: none";
}

this might help

Comments

0

Check whether PATH_INFO AND QUERY_STRING are empty...if not, then it's not the page you want.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.