-2

I need to exclude any error about it, so I ask it here. I have being asked by a client to create a page that can be accessed via a link on his website but that cannot be accessed (or at least would be redirected to another place) manually by copying the link or typing it into the browser address bar.

The only thing that came in mind to me was using a cookie on the website and then check if the user browser has stored this cookie when the critical page opens. So that another user not coming from the base website will see something different or be redirect via javascript etc. (i.g. using the cookie for an if {…).

Let me know if I oversaw a possibility or if it is simply: “There is no way to do that.” Thanks!

EDIT

@marmeladze: Sorry I am not familiar with the require techniques. So I cannot take this way I fear. And I am not able to say if it works = correct answer.

@mplungjan: Wow! Didn’t know about this seemingly very simple referrer thing! I think this is the way to go like in the accepted answer here: Checking the referrer Cool! Sadly, my link though is a direct download link of a PDF so neither of the solutions will work because I probably (I am wrong maybe?) will not be able to put code in it.

Community
  • 1
  • 1
Garavani
  • 755
  • 1
  • 13
  • 28
  • 1
    there is a way i believe. let me create a schema and post it. – marmeladze Apr 07 '17 at 08:14
  • 1
    You are likely voted down for _Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it. 1_ - your cookie idea or testing referer is a way. – mplungjan Apr 07 '17 at 08:14
  • Please read [Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers?](https://meta.stackoverflow.com/q/326569) - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions. – halfer Apr 07 '17 at 13:20
  • I have flagged your sarcastic remark as "not constructive", and it will likely be deleted by a moderator in due course. Please do not add these kinds of remarks. It is perfectly legitimate to downvote, I did so too (see edit reason for why). – halfer Apr 07 '17 at 13:21
  • You could use a referrer together with a server-side script to deliver the PDF. – halfer Apr 07 '17 at 13:22

1 Answers1

1

a solution attempt with sinatra.

require "sinatra"  

get '/posts/:slug' do
  "This is a post about #{params[:slug]}"
end

get '/*' do
  "This is an all-rounder.\n Params: #{params[:splat]}"
end

In sinatra, the topmost routes have precedence on rest. So, if your url is sth. like yoururl/posts/post-name, it will be caught by first route and will render the text "This is a post about post-name". All others will be caught by other route.

$ curl localhost:4567; echo
This is an all-rounder.
 Params: [""]
$ curl localhost:4567/posts/on-old-sage; echo
This is a post about on-old-sage
$ curl localhost:4567/posts/information-retrieval; echo
This is a post about information-retrieval
$ curl localhost:4567/posts/unbearable-lightness-of-being; echo
This is a post about unbearable-lightness-of-being
$ curl localhost:4567/make/it/as/deep/as/you/can; echo
This is an all-rounder.
 Params: ["make/it/as/deep/as/you/can"]
$ curl localhost:4567/who/is/afraid/of-hegel; echo
This is an all-rounder.
 Params: ["who/is/afraid/of-hegel"]
$ curl localhost:4567/all/socrates/knows/is/he-knows-so-little-about-things; echo
This is an all-rounder.
 Params: ["all/socrates/knows/is/he-knows-so-little-about-things"]
marmeladze
  • 6,468
  • 3
  • 24
  • 45