Jump to content

Set cookie


dreamwest

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/160871-set-cookie/
Share on other sites

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";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/160871-set-cookie/#findComment-849004
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.