Cookies!, They bit me... |
||
Welcome to the Zymic webmaster forums. Our forums are here to provide people the free ability to discuss a range of websites related topics such as design, development coding and marketing.
In order to post you will need to register for a zymic account or if you already have one simply login by using the form on the left.
Zymic Webmaster Forums Web Design & Development Client Side Scripting JavaScript |
||
![]() |
Cookies!, They bit me... |
||
Nov 30 2009, 10:57 PM
Post
#1
|
|
|
Member ![]() ![]() Group: Members Posts: 46 Joined: 1-October 09 Member No.: 112,221 |
Hello,
I have a somewhat serious issue, my cookie scripts don't work. If they dont work, my entire webpage is useless, i have included all source codes and even a link to mysite, Any and All help is appreciated. MAIN PROGRAM: (cookie.html) CODE <html> <head> <meta http-equiv="refresh" content="5"> <script type="text/javascript"> function getCookie(c_name) { if (document.cookie.length>0) { c_start=document.cookie.indexOf(c_name + "="); if (c_start!=-1) { c_start=c_start + c_name.length+1; c_end=document.cookie.indexOf(";",c_start); if (c_end==-1) c_end=document.cookie.length return unescape(document.cookie.substring(c_start,c_end)); } } return "" } function setCookie(c_name,value,expiredays) { var exdate=new Date(); exdate.setDate(exdate.getDate()+expiredays); document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : "; expires="+exdate.toGMTString()); } function checkCookie() { var username=getCookie('username'); var password=getCookie('password'); var now = new Date() var today = now.getDate() var days = today-expire; if (username!=null && username!="") { var user=prompt("Enter Your Username: "); var pass=prompt("Enter Your Password: "); if(user == username) { if(pass == password) { document.write("<font color='#A4A4A4' size='5'>Welcome "+username); } else { document.write("Error Found, Reset in 5 Seconds"); } } else { document.write("Error Found, Reset in 5 Seconds"); } } else { var username=prompt("Welcome, please enter your username:"); if (username!=null && username!="") { var exp = 5; setCookie('username',username,exp); var password=prompt("Please enter your password:"); var password2=prompt("Confirm Password:"); if(password == password2) { setCookie('password',password,exp); document.write("In a moment you will have to re-enter your data"); } else { document.write("Error In Password Set"); } } } } </script> </head> <body onLoad="checkCookie()"> </body> </html> REMOVE COOKIE (cookie_eat.html) CODE <html> <head> <script type="text/javascript"> function eat_cookie ( cookie_name ) { var cookie_date = new Date ( ); // current date & time cookie_date.setTime ( cookie_date.getTime() - 1 ); document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString(); } function ohno(){ var r=(Math.floor(Math.random()*11)); var cookie = ""; if(r>5){ cookie="Cancer Cookie"; } else{ cookie="Peanut Butter Cookie"; } var r=confirm("Are you sure you want to eat the "+cookie+"?"); if (r==true) { document.write("Noming Cookies..."); eat_cookie('username'); eat_cookie('exp'); document.write("<br>Cookies Eaten!"); document.write("<br><a href='cookie.html'>Click here to go home</a>"); } else { donothing(); } } function donothing(){ document.write("It is safe to redirect from this page, your cookie is saved<br>"); } </script> <title> Eat Cookie </title> </head> <body> <input type='button' id='eat' name='eat' value='Eat Cookie' onClick='java script:ohno()'> <input type='button' id='ew' name='ew' value='Leave Cookie' onClick='java script:donothing()'> </body> </html> LINK ( turt2live.zxq.net ) cookie_eat.html works just fine, i just posted it in case someone needed that script for whatever reason. If you need any additional data, please let me know. This same script (cookie.html) is the EXACT same script that controls all of my Login forms, and my register form is in the process of being reverted back to a standard form Thank You in advance for any help what so ever. And sorry if i just wasted an entire thread because a spelling error, i could not find one thing wrong with it.. Sincerely, Turt2 (or trut2, whichever) ((Some source code is from w3 schools )) This post has been edited by zpcs: Dec 18 2012, 01:37 PM
Reason for edit: Broken " LINK " URL Link Removed then Broken URL Link allowanced for Descriptive URL Link so as not to disturb content
|
|
|
Nov 30 2009, 11:14 PM
Post
#2
|
|
|
Member ![]() ![]() Group: Members Posts: 46 Joined: 1-October 09 Member No.: 112,221 |
*sigh** after a little scowering of the JavaScript forums, i thank Ed for mentioning firebug, it helped, ALOT, Thank you
((i had one too many variables)) |
|
|
May 2 2011, 11:07 PM
Post
#3
|
|
|
Member ![]() ![]() Group: Members Posts: 47 Joined: 15-March 11 Member No.: 182,002 |
I can't seem to open your site link...
So I can't check the error out...... |
|
|
Feb 14 2012, 07:52 PM
Post
#4
|
|
|
Newbie ![]() Group: Members Posts: 1 Joined: 14-February 12 Member No.: 230,384 |
I wasn't able to get your site either but maybe this script will help...
CODE function setCookie(name, value) { var cookieDate = new Date(2040, 11, 27, 20, 30, 30, 300); var cookieString = cookieDate.toUTCString(); document.cookie = name + "=" + value + "; expires=" + cookieString + "; path=/"; } function getCookie(name) { var toMatchCookie = name; var splitCookie = document.cookie.split("; "); var i=0, l=splitCookie.length; for (null; i < l; i++) { var partCookie = splitCookie[i].split("="); if (partCookie[0].match(toMatchCookie)) { return partCookie[1]; } } return null; } function deleteCookie(name) { var cookieName = name; var expireDate = new Date(2010, 11, 27, 20, 30, 30, 300); var expireString = expireDate.toUTCString(); document.cookie = cookieName + "=deleted; expires=" + expireString + "; path=/"; } These scripts are general purpose, and I am able to use them for a number of different purposes. You then just need to work on the layout of the page, and the script above will deal with the cookies. CODE setCookie(name, value) You need to pass a name and value for the function. The cookie lasts until 2040 and it is added at the root path. CODE getCookie(name) You need to pass a value in and it will return the value. CODE deleteCookie(name) Pass in the cookie name and it will be deleted. |
|
|
Feb 15 2012, 06:25 AM
Post
#5
|
|
|
Member ![]() ![]() Group: Members Posts: 46 Joined: 1-October 09 Member No.: 112,221 |
I didn't even realize people were still responding to this just over 2 years later, I do appreciate the responses, but I have figured it out since then (in fact, it's quite easy now compared to the other stuff I do).
|
|
|
Jun 6 2012, 06:29 AM
Post
#6
|
|
|
Newbie ![]() Group: Members Posts: 2 Joined: 6-June 12 Member No.: 244,683 |
How can I make javascript work on my computer?
|
|
|
Aug 1 2012, 11:31 AM
Post
#7
|
|
|
Member ![]() ![]() Group: Members Posts: 62 Joined: 31-July 12 Member No.: 250,988 |
Helllo guys:)
Cookie: A cookie is a small bit of text that accompanies requests and pages as they go between the Web server and browser. The cookie contains information the Web application can read whenever the user visits the site. You can add cookies to the Response.Cookies collection in a couple of ways. The following example shows two methods to accomplish the task: Response.Cookies("userName").Value = "mike" Response.Cookies("userName").Expires = DateTime.Now.AddDays(1) Dim aCookie As New HttpCookie("lastVisit") aCookie.Value = DateTime.Now.ToString aCookie.Expires = DateTime.Now.AddDays(1) Response.Cookies.Add(aCookie) The example adds two cookies to the Cookies collection, one called "userName" and the other called "lastVisit." For the first cookie, I set values of the Response.Cookies collection directly. |
|
|
![]() |
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users) |
||
| 0 Members: | ||
Forum Jump |
||
| Lo-Fi Version | Time is now: 23rd May 2013 - 08:36 PM |