I am getting the classic, "Cannot modify header information" when I try to set my cookies. The error is that headers already sent by (output started at .../myConn.php:14)
Here is my connection (myConn.php):
$LOCATION = 'localhost';
$USERNAME = 'username';
$PASSWORD = 'password';
$DATABASE = 'database';
// Connect to DB
$conn = mysql_connect($LOCATION,$USERNAME,$PASSWORD);
if (!$conn) die ("Cannot connect MySQL");
// execute connection string
mysql_select_db($DATABASE,$conn) or die ("Could not open database");
The above works properly. I call that function into the following code as follows:
require('myConn.php');
# Set cookie
setcookie('username',$username,time()+432000,'/','http://www.websiteurl.com'); //Set for 5 days
I am not having problems setting cookies or connecting. Please disregard the fact that there may be variables missing. My problem is that I do not understand why I cannot set my cookies after connecting to the database with the above code. If I try to set the cookie before connecting, it works.