Hide div with depending on URL

how to hide div with link text

for example : if my link is https://host/index.php?hide=yes ,
the </div> should be hidden…

and

if my link is https://host/index.php?hide=no ,
the </div> should be shown…

is there any way ?

if ($_REQUEST['hide']=='no' ) {
echo '</div>';
}
3 Likes

what should i do to show again ?

It should be shown when you visit https://host/index.php?hide=no

What i’ve given you is an example code, I wouldn’t be surprised if you’ve pasted that exact code there.
It must look like that:

if ($_REQUEST['hide'] != 'yes' ) {
echo 'your div element goes here';
}

.that’s why! iam a biginner…
so my doubt is can i mention a class or id

The content between the quotes can be any HTML content. The PHP code just sends whatever comes after the echo statement between quotes to the browser. So it could easily be multiple lines with multiple HTML tags with attributes, values and whatnot.

3 Likes

i have a <div> it is hidden by defult (CSS).
and also i have a button , that help to show this div,

but i need -
if i visit https://host/page.html don’t show this div and
if i visit https://host/page.html#showDiv the div must be shown …

is there any way ??

So what’s your site url?

in this way i could’nt show the popup

is this work ?!

<html>
<head>
</head>
<style>
if ($_REQUEST['hide']=='no' ) {
echo '.hiddenDiv{display:block;}';
}
</style>
<body>
<div style="display:none;" class="hiddenDiv"> <p> somthing here...</p>
</div>

</html>

NOT WORKING…

is there any way to click button using url ?

please explain how it does not show.

i just tried like this…
i don’t know is this wrong or good , but it not working …

You don’t put PHP code in HTML’s <style></style> section.
You either make a separate PHP file and call it or if you want it to be in the HTML file, you put it like so:
<?php // PHP code goes here ?>

1 Like

Could you please answer my another question. ???
This is my question .
https://forum.infinityfree.com/t/how-to-run-php-codes-in-html-files-using-htaccess/37015

The #showDiv makes this really hard. That part (the anchor tag) is not accessible from PHP code. Maybe it’s accessible with CSS, and it’s definitely accessible with Javascript, but not with PHP.

So, to fix this, you need to:

  1. Rename page.html to page.php (otherwise the PHP code won’t be executed).
  2. Change the URL to https://host/page.php?hide=yes
5 Likes

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.