Javascript
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Tutorialized ForumsWeb Design & DevelopmentJavascript

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Tutorialized Forums Sponsor:
  #1  
Old August 16th, 2004, 09:14 AM
fehers fehers is offline
Contributing User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Location: Serbia and Montenegro
Posts: 2 fehers New User: is a brand new recruit and a unknown entity at this point. 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via Yahoo to fehers
Redirect By a Javascript Cookie

I've searched the net for a javascript that writes a cookie on a users computer after going to a certain page. In other words when a page loads a javascript embedded in the <head>....</head> section automatically writes a cookie. I've found one here URL and though it is not exactly what I was looking for it serves the purpose.

The only problem is that it is "path dependent". What I want is the cookie to work within the entire domain.

The Purpose That it Serves
I have a query form on the site and after filled out and submitted the script redirects to a chosen page. This page should write the "global" cookie and after the user visits some other page (other than the original that wrote the cookie) with the same cookie script in it it should redirect to a defined page.

The url of the page that writes the cookie:
URL
the cookie is written only after the user clicks on the login button!

The url of the page that should be redirected if the cookie exists
URL

Here's the script. Once again! The code works perfectly there's nothing wrong with. I just want it to work within the entire domain.

<SCRIPT LANGUAGE="JavaScript">
<!-- 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 < 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 > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 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();
}
function cookieCreater () {
if(GetCookie('FreeStuffL') == null) {
var FreeStuffL_Name = prompt ("What name do you want to go by?", "" );
if (FreeStuffL_Name != null && FreeStuffL_Name != "") {
var expdate = new Date ();
expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 1000 * 365));
SetCookie('FreeStuffL', FreeStuffL_Name, expdate);
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 = document.login2.go.value;
}
}
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 -->
</SCRIPT>






Now the form that goes in the <body>....</body> section:

<FORM name='login'>
Enter your login codes:


<input TYPE='text' NAME='numOne' SIZE=15 value='java'>

<input TYPE='text' NAME='numTwo' SIZE=15 value='script' >

<input TYPE='text' NAME='numThree' SIZE=15 value='javascript' >

<input TYPE='button' VALUE='Login' ONCLICK='check()'>
</FORM>



<FORM name="login2">
<input type=hidden name="go" value="cookie-in.html">
</FORM>


I'd be really grateful if someone could help me with this. I tried simply deleting the highlighted areas above but it seems it works differently.

Reply With Quote
  #2  
Old August 16th, 2004, 10:23 AM
kurt kurt is offline
Contributing User
Tutorialized Novice (500 - 999 posts)
 
Join Date: Jan 2004
Posts: 508 kurt New User: is a brand new recruit and a unknown entity at this point. 
Time spent in forums: 5 m 48 sec
Reputation Power: 0
Is there a reason you're opting not to write the cookie using PHP or ASP or something similar? It's much easier to do that, and then you could simply do the redirect using javascript. This would also be more universally usable since not everyone has javascript enabled browsers.

Reply With Quote
  #3  
Old August 17th, 2004, 05:04 AM
fehers fehers is offline
Contributing User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Location: Serbia and Montenegro
Posts: 2 fehers New User: is a brand new recruit and a unknown entity at this point. 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via Yahoo to fehers
There is a reason. If I knew how to writ a script I wouldn't search the net for it. Belive it or not I spent almost 15 hours searching and this script is the most reliable for the purpose I want.

Reply With Quote
  #4  
Old August 17th, 2004, 08:53 AM
Chippo Chippo is offline
Contributing User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: Stockport, UK
Posts: 463 Chippo New User: is a brand new recruit and a unknown entity at this point. 
Time spent in forums: 23 h 32 m 47 sec
Reputation Power: 0
Send a message via MSN to Chippo
I still cant see why your using javascript instead of sumthing like php and asp as kurt said, it would be much easier and possibly less code to actually write, you could even download a script already made for this purpose. Take a look at sites like e.g. www.hotscripts.com etc and see if you cant use one of them would be much easier

Reply With Quote
  #5  
Old December 3rd, 2007, 08:49 PM
austinpilz austinpilz is offline
Registered User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Dec 2007
Posts: 2 austinpilz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 7 sec
Reputation Power: 0
Exclamation Question

Is there a way to change the access codes, I cannot figure out how!

Reply With Quote
  #6  
Old December 4th, 2007, 06:08 PM
austinpilz austinpilz is offline
Registered User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Dec 2007
Posts: 2 austinpilz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 7 sec
Reputation Power: 0
Exclamation How do you?

How do you change the passwords!

Reply With Quote
Reply

Viewing: Tutorialized ForumsWeb Design & DevelopmentJavascript > Redirect By a Javascript Cookie


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT