dreamwest Posted June 4, 2009 Share Posted June 4, 2009 Im trying to set a cookie using functions but im lost function set_cookie(object, value) { var expireDate = new Date() var expstring = expireDate.setDate(expireDate.getDate() + 500) document.cookie = object+'='+value+'; expires='+expireDate.toGMTString()+'; path=/'; $action= $_GET['action']; if($action == "off"){ function set_cookie('filter_badwords', 'off'); echo "set to off"; }elseif ($action == "on"){ function set_cookie('filter_badwords', 'on'); echo "set to on"; } This gives an error: Parse error: syntax error, unexpected ',', expecting '&' or T_VARIABLE in /user/site.com/filter.php on line 3 Quote Link to comment https://forums.phpfreaks.com/topic/160871-set-cookie/ Share on other sites More sharing options...
BK87 Posted June 4, 2009 Share Posted June 4, 2009 the first part does not make any sense as far as php, its javascript pasted into php Quote Link to comment https://forums.phpfreaks.com/topic/160871-set-cookie/#findComment-848992 Share on other sites More sharing options...
dreamwest Posted June 4, 2009 Author Share Posted June 4, 2009 the first part does not make any sense as far as php, its javascript pasted into php is there a way of setting a cookie with php instead of javascript Quote Link to comment https://forums.phpfreaks.com/topic/160871-set-cookie/#findComment-848997 Share on other sites More sharing options...
dreamwest Posted June 4, 2009 Author Share Posted June 4, 2009 Was easier than i thought <?php $action= $_GET['action']; $expire=time()+60*60*24*30; if($action == "off"){ setcookie("filter_badwords", "off", $expire, "/" ); echo "set to off"; }elseif ($action == "on"){ setcookie("filter_badwords", "on" , $expire, "/"); echo "set to on"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/160871-set-cookie/#findComment-849004 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.