|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
Restrict access based on referring URL
What is the simplest way to restrict access to a page within a site based on the referring URL? I'd like the user to receive the following message if they try to access the page via the "back door": "To access this site, you must link to it from a pre-approved URL." Please give detailed instructions if possible, as I am just a beginner.
Thanks in advance! |
|
#2
|
|||
|
|||
|
It would be best to accomplish this using server-side code (such as PHP). The reason for this, is that 1) JavaScript can be disabled and 2) if the processing occurs on the server, the "protected" content is never displayed/sent to the browser.
The actual code would be pretty straightforward. In PHP, you would use the variable $HTTP_REFERER and compare it to pre-determined URLs. Basically, if $HTTP_REFERER = "xyz" then do abc, for example: PHP Code:
__________________
Michael
|
|
#3
|
|||
|
|||
|
Thanks for the reply. I don't know anything about PHP.
Any suggestions for restricting access using Javascript? The site is actually set up for Javascript-enabled browsers only, so disabled Javascript shouldn't be a problem. |
|
#4
|
|||
|
|||
|
It would basically be the same thing, but instead of $HTTP_REFERER, you would use document.referer. Also, your page would need to be one really big JavaScript, such that the actual content is really output from the JavaScript (using document.write()).
|
![]() |
| Viewing: Dev Shed Forums > Other > Beginner Programming > Restrict access based on referring URL |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|