On a page with no output, I'm trying to set a cookie with:
//Setcookie
function mySet ($name, $value, $life = 86400) {
global $url;
setcookie($name, $value, time()+$life, "/", $url, null, true);
}
The arguments I pass are 'user'
for the name and 'Sink'
for the value.
When using var_dump(headers_list());
, it returns an empty array (array(0) { }
)
I tried using header_remove();
on the line before the setcookie just in case, but it still errors out with
Warning: Header may not contain more than a single header, new line detected in /var/www/dota/other/req.php on line 117
I have a file with a bunch of functions (just a ton of functions) that's called on every page - line 117 is the third line in the mySet()
function (setcookie()
Additionally, the cookie is not set. However, refreshing the page both removes the error and sets the cookie, even though there's no code on the entire page that checks if the page has been refreshed. I can refresh the page as many times as I want and it works. The only code on the page is:
//Update last login, along with their steam name if they changed it
$query = "UPDATE users SET steamname = ?,loginip = ? WHERE steamid = ? ";
$stmt = mysqli_stmt_init($con);
$stmt->prepare($query);
$stmt->bind_param('sss', $steamprofile['personaname'], $_SERVER["HTTP_CF_CONNECTING_IP"], $steamprofile['steamid']);
$stmt->execute();
//Get the secret key
$query = "SELECT secretkey FROM users WHERE steamid = ? ";
$stmt = mysqli_stmt_init($con);
$stmt->prepare($query);
$stmt->bind_param('s', $steamprofile['steamid']);
$stmt->execute();
$result = mysqli_fetch_assoc($stmt->get_result());
//Set the cookies
header_remove();
mySet('userKey', $result['secretkey']);
mySet('user', $steamprofile['personaname']);
var_dump(headers_list());
delCookie('type');
redir('/coach/browse.php');