How to block a user to directly access a html page on my site ?

hi there,
there is a html file in my htdocs folder which can (of course ) be directly viewed by typing in the url of the file in a browser.
i want the user to access that html page from my homepage only ,i.e. the page can’t just be viewed directly, how can this be done ??

@Rikhi55 said:
hi there,
there is a html file in my htdocs folder which can (of course ) be directly viewed by typing in the url of the file in a browser.
i want the user to access that html page from my homepage only ,i.e. the page can’t just be viewed directly, how can this be done ??

Sorry but I haven’t understood you well.
Might wanna give additional info or screenshots?

If you want to prevent a page from being linked directly from another site, you could use some PHP code to check the Referrer header of the request and block the request if the Referrer does not match your own domain. You might be able to do the same with .htaccess rules, but that would be harder.

@Admin said:
If you want to prevent a page from being linked directly from another site, you could use some PHP code to check the Referrer header of the request and block the request if the Referrer does not match your own domain. You might be able to do the same with .htaccess rules, but that would be harder.

i experimented with .htaccess file but it didn’t worked out!!!
:frowning: :frowning: :frowning: :frowning: :frowning: :frowning:
and i am not that good with php!!
any reference on how i can do that via php…

@UnknownLolz said:

@Rikhi55 said:
hi there,
there is a html file in my htdocs folder which can (of course ) be directly viewed by typing in the url of the file in a browser.
i want the user to access that html page from my homepage only ,i.e. the page can’t just be viewed directly, how can this be done ??

Sorry but I haven’t understood you well.
Might wanna give additional info or screenshots?

@UnknownLolz i want to block a user from directly going to a webpage …
for ex. by typing www.abcdsite.com/dir1/dir2/web-page.html in a browser or by the link…
i want the user to go to my home page first
by above ex. www.abcdsite.com
click on the object that takes the user to the above url…
then only the user will be able to see the web page…
Hope you get this now…

Try to learn a bit about term “hotlinking” in Google as starter, then you can refer to this: https://stackoverflow.com/questions/11895557/php-code-for-anti-hotlinking

Instead of HTML, they are talking about hotlinking image. But the method are quite similar, and I think you can fiddling a bit and settle them out.

The base64 are for image, which is irrelevant to your question

Add: The best practice of preventing direct access is using session, as stated by those people in stackoverflow. But since you’re using HTML (which is static), I couldn’t think a way to do this (or perhaps there is any as admin mentioned, my knowledge isn’t good enough).
At this point, .htaccess is the only way I could think of

@Rikhi55 said:

@UnknownLolz said:

@Rikhi55 said:
hi there,
there is a html file in my htdocs folder which can (of course ) be directly viewed by typing in the url of the file in a browser.
i want the user to access that html page from my homepage only ,i.e. the page can’t just be viewed directly, how can this be done ??

Sorry but I haven’t understood you well.
Might wanna give additional info or screenshots?

@UnknownLolz i want to block a user from directly going to a webpage …
for ex. by typing www.abcdsite.com/dir1/dir2/web-page.html in a browser or by the link…
i want the user to go to my home page first
by above ex. www.abcdsite.com
click on the object that takes the user to the above url…
then only the user will be able to see the web page…
Hope you get this now…

Try this code and insert on your .htaccess:
<Files "yourfile.html">
Order Allow,Deny
Deny from all
</Files>

@UnknownLolz said:

@Rikhi55 said:

@UnknownLolz said:

@Rikhi55 said:
hi there,
there is a html file in my htdocs folder which can (of course ) be directly viewed by typing in the url of the file in a browser.
i want the user to access that html page from my homepage only ,i.e. the page can’t just be viewed directly, how can this be done ??

Sorry but I haven’t understood you well.
Might wanna give additional info or screenshots?

@UnknownLolz i want to block a user from directly going to a webpage …
for ex. by typing www.abcdsite.com/dir1/dir2/web-page.html in a browser or by the link…
i want the user to go to my home page first
by above ex. www.abcdsite.com
click on the object that takes the user to the above url…
then only the user will be able to see the web page…
Hope you get this now…

Try this code and insert on your .htaccess:
<Files "yourfile.html">
Order Allow,Deny
Deny from all
</Files>

That code works if you want to block everyone from accessing a particular file, not just the people coming to the file directly instead of being linked internally.

I think the answer would involve rewrite rules comparing the HTTP_REFERER header. But .htaccess rules are quite complicated and confusing.

let me experiment with hotlinks and .htaccess rules,will update soon if it worked or not…
can this be done using php ??