简体   繁体   中英

how to know what files called for a php file

Here's what I want to do. I have 3 php files, one is a.php, b.php, and c.php. If a.php has a link to b.php, by using an href tag or by is using b.php as its form action. How would b.php know that it is a.php who is calling it? c.php is also linked to b.php. But I want to redirect the page to something else if it is not a.php who is using b.php.

I'm thinking of something like this for b.php,i'm just not sure how to do it in actual php code:

<?php

if(called_by('a.php')){
echo "something";
}
else{
header('location:a.php');
}

?>

The $_SERVER['HTTP_REFERER'] contain the url where the user came from.

You have to note this is sent by the user browser so it's easy to be forged, so it's not secure. Also some browsers might not send that header so it might be empty time to time.

One other possibility would be to use the session and set a flag on the page like:

$_SESSION['come_from'] = 'a';

The session solution would be more secure.

如果我正确理解了您的声音,听起来您正在尝试获取http引荐来源网址 ,您应该针对该网址查看$_SERVER['HTTP_REFERER']变量。

What about $_SERVER['HTTP_REFERER'] ?

Edit: Guess someone beat me to it

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