dreamwest Posted November 19, 2008 Share Posted November 19, 2008 im trying to set up this simple cookie script but its a bit buggy - can anyone improve this? <head><script>function set_cookie(object, value) { if (value == 'off') { var message = 'off' } else { var message = 'on' } if(confirm(message)) { var expireDate = new Date() var expstring = expireDate.setDate(expireDate.getDate() + 500) document.cookie = object+'='+value+'; expires='+expireDate.toGMTString()+'; path=/'; window.location.reload() } }</script></head> <?php if (isset($_COOKIE['customize'])) echo ""; else echo ""; if ($_COOKIE['customize'] == 'off') echo "<a href=\"javascript: set_cookie('customize', 'on');\">turn on message</a>"; else echo "<a href=\"javascript: set_cookie('customize', 'off');\">turn off message</a>"; ?> Link to comment https://forums.phpfreaks.com/topic/133320-can-anyone-improve-this/ Share on other sites More sharing options...
gevans Posted November 19, 2008 Share Posted November 19, 2008 <head><script>function set_cookie(object, value) { if (value == 'off') { var message = 'off' } else { var message = 'on' } if(confirm(message)) { var expireDate = new Date() var expstring = expireDate.setDate(expireDate.getDate() + 500) document.cookie = object+'='+value+'; expires='+expireDate.toGMTString()+'; path=/'; window.location.reload() } }</script></head> <?php if (isset($_COOKIE['customize'])) { if ($_COOKIE['customize'] === 'off') echo "<a href=\"javascript: set_cookie('customize', 'on');\">turn on message</a>"; else echo "<a href=\"javascript: set_cookie('customize', 'off');\">turn off message</a>"; } ?> Link to comment https://forums.phpfreaks.com/topic/133320-can-anyone-improve-this/#findComment-693367 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.