meme
05-29-2005, 07:46 AM
Hi all the fine developers out there,
I am trying to develop a website using PHP and Javascripting. I have 2 questions, I will post the second one in a seperate thread.
This question is about cookies. I tried to set a cookie on a user name on one page and then retrieve it on the next page. However I get the cookie displayed as:
Cookie name is 'PHPSESSID', and the value is '39f842f3b9a235bea4e1aad5dfa7411e'
Here is my code:
in the firstpage where I am setting the cookie:
expireDate = new Date
expireDate.setMonth(expireDate.getMonth()+6)
userName = ""
if (document.cookie != "") {
userName = document.cookie.split("=")[1]
}
function setCookie() {
userName = document.loginform.nameField.value
document.cookie = "userName="+enter_username+";expires=" + expireDate.toGMTString()
}
<form name="loginform" action="resultpage.php" method=post onsubmit= "return validForm(this)">
<h1>enter your login name: <input type=text name="enter_username" onblur="setCookie()"></h1>
<input type=submit value="login">
</form>
-------------
AND ON THE NEXT PAGE (RESULTPAGE), here is the code to retrieve the information:
if (document.cookie == "") {
document.write("There are no cookies here")
}
else {
thisCookie = document.cookie.split("; ")
for (i=0; i<thisCookie.length; i++) {
document.write("Cookie name is '"+thisCookie[i].split("=")[0])
document.write("', and the value is '"+thisCookie[i].split("=")[1]+"'<BR>")
}
}
I would really appreciate your prompt response.
Meme
I am trying to develop a website using PHP and Javascripting. I have 2 questions, I will post the second one in a seperate thread.
This question is about cookies. I tried to set a cookie on a user name on one page and then retrieve it on the next page. However I get the cookie displayed as:
Cookie name is 'PHPSESSID', and the value is '39f842f3b9a235bea4e1aad5dfa7411e'
Here is my code:
in the firstpage where I am setting the cookie:
expireDate = new Date
expireDate.setMonth(expireDate.getMonth()+6)
userName = ""
if (document.cookie != "") {
userName = document.cookie.split("=")[1]
}
function setCookie() {
userName = document.loginform.nameField.value
document.cookie = "userName="+enter_username+";expires=" + expireDate.toGMTString()
}
<form name="loginform" action="resultpage.php" method=post onsubmit= "return validForm(this)">
<h1>enter your login name: <input type=text name="enter_username" onblur="setCookie()"></h1>
<input type=submit value="login">
</form>
-------------
AND ON THE NEXT PAGE (RESULTPAGE), here is the code to retrieve the information:
if (document.cookie == "") {
document.write("There are no cookies here")
}
else {
thisCookie = document.cookie.split("; ")
for (i=0; i<thisCookie.length; i++) {
document.write("Cookie name is '"+thisCookie[i].split("=")[0])
document.write("', and the value is '"+thisCookie[i].split("=")[1]+"'<BR>")
}
}
I would really appreciate your prompt response.
Meme