/    Sign up×
Community /Pin to ProfileBookmark

Need Security Script

I need a script to check which url the page came from and if it is not correct it will redirect to an access denined page. For example, if i come to a page from ‘link1’ it will let me in, but if i come to a page from ‘link2’ or any other link i will be redirected.

Thanks all who can help

P.S. I cant seem to get a dhtml menu working if it is in a .php file (sothink DHTMLmenu) so i cant use php. Thanks!

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@CrazyMerlinJan 01.2006 — for the url checking, use document.referrer

it will contain the link of the referring document, unless it has been blocked, which in most cases won't be true
Copy linkTweet thisAlerts:
@SkitzJan 01.2006 — Hey David, Merlin is right, you can use the referrer, or you can also use a cookie script as well. I've found it useful on a few occasions , when making user profiles and such.

If the user doesn't have a cookie ,that he got from the previous page ,the page will redirect him to page two, otherwise if the user has the cookie then it lets him stay.

Here's the code:

Put this part in your head tags

<i>
</i>&lt;SCRIPT LANGUAGE="JavaScript"&gt;

&lt;!-- This script and many more are available free online at --&gt;
&lt;!-- The JavaScript Source!! http://javascript.internet.com --&gt;

&lt;!-- Begin
function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i &lt; clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc &gt; 2) ? argv[2] : null;
var path = (argc &gt; 3) ? argv[3] : null;
var domain = (argc &gt; 4) ? argv[4] : null;
var secure = (argc &gt; 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}
function DeleteCookie () {
var exp = new Date();
exp.setTime (exp.getTime() - 1000000000); // This cookie is history
var cval = GetCookie ('FreeStuffL');
document.cookie ='FreeStuffL' + "=" + cval + "; expires=" + exp.toGMTString(); <br/>
}
function cookieCreater () {
if(GetCookie('FreeStuffL') == null) {
var FreeStuffL_Name = prompt ("What name do you want to go by?", "" );
if (FreeStuffL_Name != null &amp;&amp; FreeStuffL_Name != "") {
var expdate = new Date ();
expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 1000 * 365));
SetCookie('FreeStuffL', FreeStuffL_Name, expdate); <br/>
alert ("You now are logged in! From now on, when you come to this page, you will be forwarded to the Password Protected Members-Only Area. Please do not tell anyone your entry code. At this new page, you will be shown a list of functions. Have fun!");
location.href = "cookie-in.html"
}
}
else {
DeleteCookie ();
cookieCreater ()
}
}
if(GetCookie('FreeStuffL') != null) {
location.href="cookie-in.html"
}
function check() {
var tester = document.login.numOne.value + document.login.numTwo.value;
if (tester == "") {
alert ("I'm sorry, that code is not correct.");
}
else
{
if (tester == document.login.numThree.value) {
alert ("That is correct!");
cookieCreater ();
}
else {
alert ("Nope!");
}
}
}
// End --&gt;
&lt;/SCRIPT&gt;


ok now that you did that, now paste this part in your body
<i>
</i>&lt;BODY&gt;

&lt;center&gt;
&lt;form name='login'&gt;
Enter your login code (FORMAT: login # one, login # two, login # three):
&lt;p&gt;&lt;input TYPE='text' NAME='numOne' SIZE=15&gt;&lt;br&gt;
&lt;input TYPE='text' NAME='numTwo' SIZE=15 &gt;&lt;br&gt;
&lt;input TYPE='text' NAME='numThree' SIZE=15 &gt;&lt;br&gt;
&lt;input TYPE='button' VALUE='Login' ONCLICK='check()'&gt;
&lt;/form&gt;
&lt;/center&gt;
&lt;font size=1 color=white&gt;
This page requires Javascript to run! Please get Netscape 2.0 or greater!
&lt;/font&gt;
&lt;form name="login2"&gt;
&lt;input type=hidden name="go" value="cookie-in.html"&gt;
&lt;/form&gt;

&lt;p&gt;&lt;center&gt;
&lt;font face="arial, helvetica" size="-2"&gt;Free JavaScripts provided&lt;br&gt;
by &lt;a href="http://javascriptsource.com"&gt;The JavaScript Source&lt;/a&gt;&lt;/font&gt;
&lt;/center&gt;&lt;p&gt;


i hope this helped you at all

Skitz -

Three can keep a secret, if two are dead.

Two
Copy linkTweet thisAlerts:
@david5220authorJan 01.2006 — Thanks!!! ? ?

How do i install it?
Copy linkTweet thisAlerts:
@SkitzJan 01.2006 — I'm not quite sure as of what you mean by installing the javascript. All you need to do to get it to run is simply paste that code , like the directions tell you, in your html page of you're website and it should work.

If you have any other questions , you can fee lfree to email me at [email][email protected][/email]
×

Success!

Help @david5220 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.19,
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,
)...