Skip to main content
Added notes
Source Link
Pat J
  • 12.3k
  • 2
  • 28
  • 36

setcookie() has the following signature:

setcookie ( $name, $value = "", $expires = 0, $path = "", $domain = "", $secure = FALSE, $httponly = FALSE )

You're setting the cookie's value to 1 in your code. I suspect you intend to do something more like

setcookie('language', $_GET['language'], time() + 1209600, "/", "example.com", false);

Notes

  • This answer doesn't address the security issues in trusting that the $_GET data is clean. You should research data sanitization.
  • WordPress provides a bunch of handy constants to make something like time() + 1209600 easier to read. You can do something like time() + ( 2 * WEEK_IN_SECONDS ), for example.

setcookie() has the following signature:

setcookie ( $name, $value = "", $expires = 0, $path = "", $domain = "", $secure = FALSE, $httponly = FALSE )

You're setting the cookie's value to 1 in your code. I suspect you intend to do something more like

setcookie('language', $_GET['language'], time() + 1209600, "/", "example.com", false);

setcookie() has the following signature:

setcookie ( $name, $value = "", $expires = 0, $path = "", $domain = "", $secure = FALSE, $httponly = FALSE )

You're setting the cookie's value to 1 in your code. I suspect you intend to do something more like

setcookie('language', $_GET['language'], time() + 1209600, "/", "example.com", false);

Notes

  • This answer doesn't address the security issues in trusting that the $_GET data is clean. You should research data sanitization.
  • WordPress provides a bunch of handy constants to make something like time() + 1209600 easier to read. You can do something like time() + ( 2 * WEEK_IN_SECONDS ), for example.
Source Link
Pat J
  • 12.3k
  • 2
  • 28
  • 36

setcookie() has the following signature:

setcookie ( $name, $value = "", $expires = 0, $path = "", $domain = "", $secure = FALSE, $httponly = FALSE )

You're setting the cookie's value to 1 in your code. I suspect you intend to do something more like

setcookie('language', $_GET['language'], time() + 1209600, "/", "example.com", false);