简体   繁体   中英

Redirect to index.php when directly access any php page in root folder

there is one file called reports.php. if someone directly accessed 192.168.1.1/reports.php it should redirect to index.php prevent the direct access from users to reports.php through step by step procedure only they can reach reports.php

For а case you described, you need to specify a condition in the reports.php file that results in deciding to do a redirect or execute your business logic. For example, if you use get parameters you can do this:

if (!isset($_GET["step"])) {
   // do redirect
}
// do business logic

The example uses the query parameter step . You can also use the session extension built-in to php using the global variable $_SESSION

You can see how to redirect here: How do I make a redirect in PHP?

you can use sessions, https://www.php.net/manual/en/book.session.php

on your index.php start session with name and check on everyother page if the session exist, if not redirect to index.php

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