close ad
WARNING: Do Not Install the DREAMWEAVER CC 2017 or 2018 Update »
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Clear Cookies

Thread began 8/13/2011 11:00 am by sanj.shah88633 | Last modified 5/27/2015 6:46 pm by Ray Borduin | 1642 views | 7 replies |

sanj.shah88633

Clear Cookies

Hi,

I have added the cookies to my page and this works fine (triggered by a checkbox) as per the demo, however when I uncheck the tickbox not to store the cookies they are still saved?

Any help is appreciated.

This is my code:

<%
if (cStr(cStr(Request.Form("remember"))) <> "") then
myExpire = DateAdd("d", 30, Now())
cookieName = "uname"
Response.Cookies(cookieName) = "" & cStr(cStr(Request.Form("useremail"))) & ""
Response.Cookies(cookieName).Expires = myExpire
Response.Cookies(cookieName).Path = "/"
if ("" <> "") then
Response.Cookies(cookieName).Domain = ""
end if
Response.Cookies(cookieName).Secure = 0
end if
%>
<%
if (cStr(cStr(Request.Form("remember"))) <> "") then
myExpire = DateAdd("d", 30, Now())
cookieName = "pname"
Response.Cookies(cookieName) = "" & cStr(cStr(Request.Form("password"))) & ""
Response.Cookies(cookieName).Expires = myExpire
Response.Cookies(cookieName).Path = "/"
if ("" <> "") then
Response.Cookies(cookieName).Domain = ""
end if
Response.Cookies(cookieName).Secure = 0
end if
%>
<%
if (cStr(cStr(Request.Form("remember"))) <> "") then
myExpire = DateAdd("d", 30, Now())
cookieName = "remember"
Response.Cookies(cookieName) = "1"
Response.Cookies(cookieName).Expires = myExpire
Response.Cookies(cookieName).Path = "/"
if ("" <> "") then
Response.Cookies(cookieName).Domain = ""
end if
Response.Cookies(cookieName).Secure = 0
end if
%>


<form id="form1" name="form1" method="POST" action="<%=MM_LoginAction%>">
<table width="450" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="56">&nbsp;</td>
<td width="302">
<table width="364" border="0" cellpadding="4" cellspacing="0" class="mytable">
<tr>
<td height="25" colspan="3"><legend class="PageHeader">Reviewer Login</legend></td>
</tr>
<tr>
<td width="118" rowspan="4"><img src="images/admin.png" width="118" height="118" /></td>
<td width="58" height="35">Username</td>
<td width="188"><input name="useremail" type="text" id="useremail" value="<%=cStr(Request.Cookies("uname"))%>" /></td>
</tr>
<tr>
<td height="35">Password</td>
<td><input name="password" type="password" id="password" value="<%=cStr(Request.Cookies("pname"))%>" /></td>
</tr>
<tr>
<td height="35">&nbsp;</td>
<td><input name="remember" type="checkbox" id="remember" value="checkbox" <%If (CStr(cStr(Request.Cookies("remember"))) = CStr("1")) Then Response.Write("checked=""checked""") : Response.Write("")%> />
<label for="remember"></label>
Remember Me</td>
</tr>
<tr>
<td><input type="submit" name="button" id="button" value="Logon" /></td>
<td>&nbsp;</td>
</tr>
</table>
</td>
</tr>
</table>
</form>

Sign in to reply to this post

Jason ByrnesWebAssist

you would need to add code to the page to clear the cookies if the remeber button is unchecked:


<%
if (cStr(cStr(Request.Form("remember"))) = "" && cStr(cStr(Request.Form("button"))) <> "") then
myExpire = DateTime.Now.AddDays(-1D)
cookieName = "uname"
Response.Cookies(cookieName) = "" & cStr(cStr(Request.Form("useremail"))) & ""
Response.Cookies(cookieName).Expires = myExpire
Response.Cookies(cookieName).Path = "/"
if ("" <> "") then
Response.Cookies(cookieName).Domain = ""
end if
Response.Cookies(cookieName).Secure = 0
end if
%>
<%
if (cStr(cStr(Request.Form("remember"))) = "" && cStr(cStr(Request.Form("button"))) <> "") then
myExpire = DateTime.Now.AddDays(-1D)
cookieName = "pname"
Response.Cookies(cookieName) = "" & cStr(cStr(Request.Form("password"))) & ""
Response.Cookies(cookieName).Expires = myExpire
Response.Cookies(cookieName).Path = "/"
if ("" <> "") then
Response.Cookies(cookieName).Domain = ""
end if
Response.Cookies(cookieName).Secure = 0
end if
%>
<%
if (cStr(cStr(Request.Form("remember"))) = "" && cStr(cStr(Request.Form("button"))) <> "") then
myExpire = DateTime.Now.AddDays(-1D)
cookieName = "remember"
Response.Cookies(cookieName) = "1"
Response.Cookies(cookieName).Expires = myExpire
Response.Cookies(cookieName).Path = "/"
if ("" <> "") then
Response.Cookies(cookieName).Domain = ""
end if
Response.Cookies(cookieName).Secure = 0
end if
%>
Sign in to reply to this post

sanj.shah88633

Thanks Jason, I thought the extension would do both parts save/delete cookies as required.
but can see how this works now from your code.

Regards,

Sanjay

Sign in to reply to this post

Gizza372666

About clear the cookies if the user tick the box

Hi,
I have bought the cookie ext but I haven't used it yet.
Now with the new EU law, can you please let me know/send me the code which I can put on a form to give the option to users to store or delete cookies?
e.g. Message: 'This page contain cookies. Do you accept cookies | Yes | No |'
if they tick the Yes option, they can continue and if they select No the cookies will be removed. I use PHP.
thanks

Sign in to reply to this post

Jason ByrnesWebAssist

add the radio group and submit button. set the checked value for yes button to 1 and leave the checked value for the no button blank


add a set cookie behavior for each cookie you may have set, for the trigger select the radio group, and set the expiration date to a date in the past. Using a data in the past will delete the cookie

Sign in to reply to this post

info4753

Hi Jason. Can you please provide php code on hoe to clear a cookie when the remember me checkbox is not selected?

This doesn't seem to work:

<?php
if ((isset($_POST["LogIn_submit"])&&(isset($_POST["Log_In_group_3_Remember_my_information"])) && $_POST["Log_In_group_3_Remember_my_information"] == "")) {
setcookie("RememberMeUN", "".((isset($_POST["Log_In_group_Username"]))?$_POST["Log_In_group_Username"]:"") ."", time()+(60*60*24*-1), "/", "", 0);
}
?>

Sign in to reply to this post

Ray BorduinWebAssist

try:

php:
<?php

if (isset($_POST["LogIn_submit"]) && !isset($_POST["Log_In_group_3_Remember_my_information"])) {
setcookie("RememberMeUN"""time()+(60*60*24*-1), "/"""0);
}
?>
Sign in to reply to this post

info4753

Thanks Ray, I'll give it a try.

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...