If I try accessing a certain page (eg, file.html
) via its URL, I get redirected (eg, to enroll.html
). But if I go through enroll.html
I won't get redirected.
Is that possible? If so, how?
You can validate the referer with javascript ( document.referrer
) or with php ( $_SERVER['HTTP_REFERER']
)
if(document.referrer != 'http:// - - - /enroll.html')
window.location.replace("http:// - - - /enroll.html")
if($_SERVER['HTTP_REFERER'] != 'http:// - - - /enroll.html')
header('Location: http:// - - - /enroll.html');
https://developer.mozilla.org/en-US/docs/Web/API/Document/referrer http://php.net/manual/en/reserved.variables.server.php
Dont rely solely on this, as it can be easily faked.
You can use document.referrer
to achieve this with JS.
Example:
function func() {
if (document.referrer == "whatever page") {
//TODO enter code
} else {
window.location = "whatever page";
}
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.