Join us at IRC!
Hacking isn't just Computers & Exploits. It's a Philosophy. - Mr_Cheese
Thursday, May 24, 2012
Navigation
Members Online
Total Online: 30
Web Spiders: 15
Guests Online: 30
Members Online: 0

Registered Members: 70188
Newest Member: nuk3d
Latest Articles
View Thread

HellBound Hackers | Computer General | Programming

Author

Help with a small javascript cookie create/read script?

bostikpaste1
Member

Posts: 11
Location: Australia
Joined: 05.12.08
Rank:
Moderate
Posted on 12-12-09 04:04
I have written a small scblockedript that , when a button is clicked, allows the user to input a name, value and number of days until the cookie has expired using prompt popups. The input works, my problem arises when i click the read button. It should displa an alert with the value of the cookie except nothing happens. I have looked for quite a while and cannot find what hte problem is.

Here is the scblockedript:

<body>
<input type = button value = "Create Cookie" onblockedclick = "getcookiedata()">
<input type = button value = "Read Cookie" onblockedclick = "readcookie(name)">
</body>

<scblockedript>


function getcookiedata(){
name = prompt("Enter the cookie name");
value = prompt("Enter the cookie value");
expires = prompt("Enter the number of days until it expires");
createCookie(name, value, expires);
}




function createCookie(name, value, expires){
document.cookie = name+"="+value; expires = expires;
}



function readcookie(name){
var cookiename = name + "=";
cookie_array = document.cookie.split(';');
for(i = 0; i < cookie_array.length; i++){
cookie = cookie_array[i];
while(cookie.charAt(0)==' '){
cookie = cookie.substring(1,cookie.length);
}
if(cookie.indexOf(cookiename) == 0){
alertbox = cookie.substring(cookiename.length, cookie.length);
alert(alertbox);
}
}
}

</scblockedript>

If this is the wrong place to be pasting code, please let me know.
Thanks for any help.
freddymcfudge@hotmail.com
Author

RE: Help with a small javascript cookie create/read script?

define
Member

Posts: 201
Location:
Joined: 13.12.08
Rank:
Moderate
Warn Level: 1
Posted on 12-12-09 04:20
Use the Error Console in Firefox to see what error is being encountered. Unless you made an error in pasting the JS into the forum, you made a mistake in your "createCookie" function, not the "readCookie" one.


If you need to contact me, send me a PM. I will read and/or respond in time.
Guest
Username

Password

Remember Me


Bookmark This Page
Affiliates
Adverts

 

 

Links
By using, viewing or obtaining any information contained on this site, you agree to the disclaimer.

© HellBound Hackers 2008- 2009. Since 3rd December 2004.