Reputation: 1297
I'm beginner in php and want to know if I have page A.php ,B.php and C.php and page A.php send request to page C.php how can i know that the request come from A.php not any other page. Thanks
Upvotes: 1
Views: 620
Reputation: 20823
Simplistically, within C.php:
<?php
if ($_SERVER['HTTP_REFERER'] == 'http://www.somesite.com/A.php'){
// Do it
} else {
// Do not
}
To improve reliability, it's possible to use other data (eg. session variables) passed (and more so if you're using forms). If its just a straight link with nothing else, its more difficult.
Upvotes: 0
Reputation: 476
I would add a variable to the GET array of the URL call and check that - www.yoururl.com/pageC?callingPage=a Something like that. The referrer variable isnt necissarily reliable :/ Also, since you need to know what page you're coming from, wouldn't you also be therefore doing something with that page's data? If that's the case, you could pass the identification variable with the data being sent anyways. If not, then you could still use the method I just mentioned.
Upvotes: 0
Reputation: 10061
Check out php's $_SERVER variable. It sounds like you want to use $_SERVER['HTTP_REFERER]
.
Note: This is not going to be 100% accurate as it uses the information from the browsers user agent, which can be spoofed and some don't send that information at all.
There is no 100% guaranteed way of having this information, though that would be your best bet.
Upvotes: 0