Jump to content

sijugeorge

New Members
  • Posts

    1
  • Joined

  • Last visited

sijugeorge's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Cookies are sent in the headers of the transmission of the HTTP page. Once you give some output, you cannot modify these anymore. The problem in your case lies in you outputting some of the HTML-document before trying to set the cookie. There are a few ways to solve it; one of which is setting the cookie prior to outputting anything on the page like so <?php $value = 'something from somewhere'; setcookie("TestCookie", $value); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title></title> </head> <body> </body> </html> Alternatively, you could buffer your output so that nothing gets written until you explicitly tell it to <?php ob_start(); // Initiate the output buffer ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title></title> </head> <body> <?php $value = 'something from somewhere'; setcookie("TestCookie", $value); ?> </body> </html> <?php ob_end_flush(); // Flush the output from the buffer ?> Hope you have understood the point.
×
×
  • 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.