开发者

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 actio开发者_开发百科n. 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.


If I am understanding you correctly, it sounds like you are trying to get the http referrer, for which you should look at the $_SERVER['HTTP_REFERER'] variable.


What about $_SERVER['HTTP_REFERER']?

Edit: Guess someone beat me to it

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜