简体   繁体   中英

In php how to hide contents of a page if url not matched

I have a page demo.php. In this page I have some contents. Also I am passing values to the URL demo.php?id=1. This url generates dynamically. This url has some contents.

I want to hide the contents of demo.php in demo.php?id=1.

My Logic

if(basename(__FILE__, '.php')=='demo'){
//Show demo.php contents
}
else{
$id=$_GET['id'];
}

This is not working. This only hides the content of demo.php?id=1 in demo.php Not hiding the content of demo.php in demo.php?id=1

Please help me to solve to hide the content of demo.php in demo.php?id=1.

Test for ?id= instead of the file name

if(!isset($_GET['id'])){
//Show demo.php contents
}
else{
$id=$_GET['id'];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM