προβλημα ανακτησης cookie

Συζητήσεις για θέματα που σχετίζονται με software.
Post Reply
User avatar
nocturna_gr
byte level
byte level
Posts: 122
Joined: Tue Sep 27, 2005 2:20 pm

προβλημα ανακτησης cookie

Post by nocturna_gr » Sat Dec 30, 2006 3:17 pm

Γεια,
βρηκα λιγο κωδικα στο ιντερνετ για την αποθηκευση και ανακτηση cookies. Την αποθηκευση την κανω επιτυχως, αλλα δεν μπορω να τα ανακτησω επιτυχώς, απο άλλη σελίδα ομως, αν και βρισκεται και αυτή παρακάτω στο "μονοπάτι", στο οποίο δηλώνω το cookie ως valid.

Πιο συγκεκριμενα:
Χρησιμοποιω τη μεθοδο setCookie με το valid μονοπατι hardcoded. Η μεθοδος οριζεται στο "/home/kostas/9sem/hci/profiles/profile_user.html" και ισυει στο μονοπατι "/home/kostas/9sem/hci/"

Code: Select all

function setCookie(cookieName,cookieValue,expiration)
{
	expirationDate=new Date();
	expirationDate=expirationDate.valueOf()+expiration*24*60*60*1000;
	expirationDate=new Date(expirationDate);						
	expires=";expires="+expirationDate.toGMTString();
	path=";path="+x.href;
	theCookie=cookieName+"="+escape(cookieValue)+path+expires;		
	document.cookie=theCookie;		
}
Μετα προσπαθω να ανακτησω το cookie, χρησιμοποιωντας αυτο τον κωδικα, που ειναι ορισμενος στο "/home/kostas/9sem/hci/control_panel.html".

Code: Select all

...
	if (getCookie("married").value=="true")
	{
		window.open(x.href+"profile_wife.html","_self")			
	}
	else
...
function getCookie(c_name)
{
	var parent=window.parent.parent.document;
	if (parent.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 ""
}
Post Reply

Return to “Software”