/    Sign up×
Community /Pin to ProfileBookmark

Redirection based on referring URL

I’m trying to find a code that will redirect a user to a login page if they are trying to access a page within a certain directory of our website from outside of that directory. Basically, if the page they came from isn’t within [url]http:///www.mysite/catalog/[/url] , they should be redirected. I found some codes that cover if it isn’t coming from a specific page…but I need it to be anything within that directory..

Thanks for any help in advance!

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@UltimaterNov 14.2005 — document.referrer contains a string, blank in some cases becase of browser settings etc, that the user came from. I'd suggest sending a "get" method parameter over to your other page, and reading it with JavaScript to figure out where to redirect them to. You could even do this in PHP and serve users with JavaScript disabled by reading parameters.

Here's an example showing how JavaScript can read the querystring:

http://www.aplustv.com/public_stuff/querystring1.htm
×

Success!

Help @vegas1211 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...