• Hi,
    I’m trying to make a cookie sesion manually in php but when I write php code in one page, I have this error:

    Warning: session_start(): Cannot send session cookie – headers already sent by (output started at C:\xampp\htdocs\sunwaychessfestival\wp-content\plugins\sitepress-multilingual-cms\inc\language-switcher.php:1038) in C:\xampp\htdocs\sunwaychessfestival\wp-content\plugins\shortcode-exec-php\shortcode-exec-php-class.php(895) : eval()’d code on line 1

    Warning: session_start(): Cannot send session cache limiter – headers already sent (output started at C:\xampp\htdocs\sunwaychessfestival\wp-content\plugins\sitepress-multilingual-cms\inc\language-switcher.php:1038) in C:\xampp\htdocs\sunwaychessfestival\wp-content\plugins\shortcode-exec-php\shortcode-exec-php-class.php(895) : eval()’d code on line 1

    I read and I think this is because session_start has to be in the first line of any php code, and this happens because firstly there is the function.php file.
    But I don’t know how to fix that cause I only need the session_start in 3 pages, so I want to put in this pages the code.

    I hope somebody can help me with that.
    Thank you,

    Gemma

Viewing 1 replies (of 1 total)
  • Hi, Gemma,

    Cookies are sent inside HTTP headers which precede any HTML that the server sends to the browser. So what you need to do is make sure you set your cookie prior to any HTML having been sent to the browser. The correct way to do this is to attach your code in the appropriate WordPress hooks that runs as early as possible during each request. This hook might be the ‘init’ hook or ‘theme_init’, but this is something you will have to decicde for yourself according to your specific needs and the rest of the code that you are using (theme, plugins, etc).

Viewing 1 replies (of 1 total)
  • The topic ‘Cannot send session cookie’ is closed to new replies.