0

Already searched all topics regarding this question but none of the answers helped me so I'm posting a new question.

I have my page index.php which has php include that all navigation links open in the same index.php. For example when I click about us it opens index.php?page=aboutus.

My problem is I have a div on my homepage:

<div class="icons_small"> 
<a href="#"><img src="images/layout/facebook_icon_s.png" width="75" height="67" /></a>
<a href="#"><img src="images/layout/twitter_icon_s.png" width="75" height="67" /></a>
<a href="#"><img src="images/layout/youtube_icon_s.png" width="75" height="67" /></a>
<a href="#"><img src="images/layout/location_icon_s.png" width="75" height="67" /></a>
</div>

For this div, I want him to be hidden in index.php but I want it to be visible on all other pages like index.php?page=aboutus, index.php?page=contact etc.

Is there any simple way to do this with php? :)

Thx in advance.

3 Answers 3

1

Try this. If the GET parameter page isn't set or doesn't have a value, it will hide the div.

<?php
if(isset($_GET['page']) && $_GET['page'] != "") {
?>
<div class="icons_small"> 
<a href="#"><img src="images/layout/facebook_icon_s.png" width="75" height="67" /></a>
<a href="#"><img src="images/layout/twitter_icon_s.png" width="75" height="67" /></a>
<a href="#"><img src="images/layout/youtube_icon_s.png" width="75" height="67" /></a>
<a href="#"><img src="images/layout/location_icon_s.png" width="75" height="67" /></a>
</div>
<?php
}
?>
Sign up to request clarification or add additional context in comments.

1 Comment

No problem. If my answer has solved your problem, choose it as the accepted answer.
0

This would depend on how the pages are being included.

If we are using PHP's echo to print out the HTML, we could simply choose to not print that specific section out with echo when page is not set (that is, there is no page=whatever).

if(!isset($_GET['page'])
{
    echo 'The contents of the div that shouldn't be on the page';
}

If for whatever reason you cannot selectively print sections, a messy alternative would be to echo some JavaScript which would remove the div. However, this has the crucial flaw that the div would still be shown for users who have JavaScript disabled.

Comments

0

This is not secure at all. I understand it's all about 4 images but learning from a bad practice could be fatal for other projects.

What would happen if I write "index.php?page=I_WANT_TO_SEE_THAT_BOX" ?

What I would suggest is, check should you display it or not directly in your including function. I assume you have something like

function IncludeView() {
  $allowed_pages = array("view","friends","foo","bar");
  if(isset($_GET['page'])) {
    if(in_array($_GET['page'],$allowed_pages)) {
      include_once(PAGE_DIR."/".$_GET['page'].".php");  
      define("IS_PAGE_OKAY",true);
    }
  }
  else header(BASE_URL);
}
IncludeView();

Later in your template:

<?php if(defined("IS_PAGE_OKAY")) { ?>
   //your html code that is shown only on other pages than index.php
<?php } ?>

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.