Limiting Access

  • Thread starter Thread starter Rob
  • Start date Start date
R

Rob

Is there a way to control entrance to my website? What I mean is there a
way to make sure people have to come thru my index page before accessing
anywhere else?

I guess there is a way to do this because the pay sites do it all the time
so I guess I am really asking how to do it. My site is not a pay site. I
just want folks to come in a certain way.


thanks
 
Yes, for sure
Although some experts here have frowned on it.

In every page, place this
<body onload="detect();">
where detect() is a function in a linked external JS file
(Use this in the head section: <script type="text/javascript"
src="scripts/external.js"></script> )

function detect()
{
if (parent.location.href == window.location.href)
parent.location.href = "index.html" // Put your home page here
}

It says that if you entered this page direct, load "index.html"

At least this works or me, where I have frames. Perhaps parent.location
isn't defined when there are no frames. (As a relative beginner, I am not
sure about this point.)
 
Any script like that in a no frames site will make it impossible to
open any other page, even from the home page.
You need to check if the home page has been visited, and that means
checking for a cookie or session variable before doing the
redirection.
Using a session variable is the best way, since it requires server
side scripting (ASP, PHP, Perl/CGI etc.) but JavaScript cookies will
also work, except where the user has JavaScript and/or cookies
disabled.
See http://irt.org/script/cookie.htm for information on setting and
reading JavaScript Cookies - you may be able to adapt
http://irt.org/script/1360.htm to your needs.
 
I'd check for a referer on each page if it's blank or not from your site
then redirect to the home page -
<script>
if(!document.referer || document.referer.indexOf('you.com')
== -1)location.replace('index.htm');
</script>
 
Jon,
I was interested to see what the value of referer was

I have this code in index_main.html (a frame)
<a href="bettercalc.html">

In bettercalc.html, I have this code in the head
<script type="text/javascript">
alert(location.href + ' ' + document.referer)
</script>

The alert returns the location of bettercalc.html (on C: drive, as I am
testing locally) and 'undefined'

Why is it 'undefined' and not 'index_main.html'

I tried the same thing from a new file 'test.html' (not a frame) and got the
same result
 
Undefined because your PC is not from a valid URL
- test it on line on a server

--




| Jon,
| I was interested to see what the value of referer was
|
| I have this code in index_main.html (a frame)
| <a href="bettercalc.html">
|
| In bettercalc.html, I have this code in the head
| <script type="text/javascript">
| alert(location.href + ' ' + document.referer)
| </script>
|
| The alert returns the location of bettercalc.html (on C: drive, as I am
| testing locally) and 'undefined'
|
| Why is it 'undefined' and not 'index_main.html'
|
| I tried the same thing from a new file 'test.html' (not a frame) and got the
| same result
|
| --
| Cheers,
| Trevor L.
| Website: http://tandcl.homemail.com.au
|
| Jon Spivey wrote:
| > I'd check for a referer on each page if it's blank or not from your
| > site then redirect to the home page -
| > <script>
| > if(!document.referer || document.referer.indexOf('you.com')
| > == -1)location.replace('index.htm');
| > </script>
| >
| > --
| > Cheers,
| > Jon
| > Microsoft MVP
| >
| > | >> Any script like that in a no frames site will make it impossible to
| >> open any other page, even from the home page.
| >> You need to check if the home page has been visited, and that means
| >> checking for a cookie or session variable before doing the
| >> redirection. Using a session variable is the best way, since it
| >> requires server side scripting (ASP, PHP, Perl/CGI etc.) but
| >> JavaScript cookies will also work, except where the user has
| >> JavaScript and/or cookies disabled. See http://irt.org/script/cookie.htm
| >> for information on setting and
| >> reading JavaScript Cookies - you may be able to adapt
| >> http://irt.org/script/1360.htm to your needs.
| >> --
| >> Ron Symonds
| >> Microsoft MVP (FrontPage)
| >> Reply only to group - emails will be deleted unread.
| >>
| >> | >>> Yes, for sure
| >>> Although some experts here have frowned on it.
| >>>
| >>> In every page, place this
| >>> <body onload="detect();">
| >>> where detect() is a function in a linked external JS file
| >>> (Use this in the head section: <script type="text/javascript"
| >>> src="scripts/external.js"></script> )
| >>>
| >>> function detect()
| >>> {
| >>> if (parent.location.href == window.location.href)
| >>> parent.location.href = "index.html" // Put your home page
| >>> here }
| >>>
| >>> It says that if you entered this page direct, load "index.html"
| >>>
| >>> At least this works or me, where I have frames. Perhaps
| >>> parent.location isn't defined when there are no frames. (As a
| >>> relative beginner, I am not sure about this point.)
| >>> --
| >>> Cheers,
| >>> Trevor L.
| >>> Website: http://tandcl.homemail.com.au
| >>>
| >>> Rob wrote:
| >>>> Is there a way to control entrance to my website? What I mean is
| >>>> there a way to make sure people have to come thru my index page
| >>>> before accessing anywhere else?
| >>>>
| >>>> I guess there is a way to do this because the pay sites do it all
| >>>> the time so I guess I am really asking how to do it. My site is
| >>>> not a pay site. I just want folks to come in a certain way.
| >>>>
| >>>>
| >>>> thanks
|
|
 
Or could it be because 'referer' should be spelt 'referrer'

Anyway, I'll try changing the spelling
 
To any who are following this thread:

When I changed the spelling, document.referrer returned blank

The same ocurred whether called from a frame or a normal HTML file
 
referer, is not misspelled

--
==============================================
Thomas A. Rowe (Microsoft MVP - FrontPage)
==============================================
If you feel your current issue is a results of installing
a Service Pack or security update, please contact
Microsoft Product Support Services:
http://support.microsoft.com
If the problem can be shown to have been caused by a
security update, then there is usually no charge for the call.
==============================================
 
See:
http://en.wikipedia.org/wiki/Referer

--
==============================================
Thomas A. Rowe (Microsoft MVP - FrontPage)
==============================================
If you feel your current issue is a results of installing
a Service Pack or security update, please contact
Microsoft Product Support Services:
http://support.microsoft.com
If the problem can be shown to have been caused by a
security update, then there is usually no charge for the call.
==============================================
 
Thank you, Thomas

To all,
Using the spelling document.referrer, I find that a correct value will be
returned online, but not locally (as you said, Stefan)
 
Hi Trevor,

You're right of course referrer is the correct spelling. My excuse is that
it's spelt referer in asp :-)
 
Back
Top