Jump to content

setcookie() expects paramater to be long.


turpentyne

Recommended Posts

I'm stumped on this one. New to sessions and cookies. When somebody logs out, the browser goes to logout.php. It logs them out, but the page shows this error:

 

Warning: setcookie() expects parameter 3 to be long, string given in /data/21/2/40/160/2040975/user/2235577/htdocs/logout.php on line 23

you are now logged out.

 

<?php 

session_start();

if(!($_SESSION[id])){

$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_server['PHP_SELF']);

// check for trailing slash

if ((subst($url, -1) == '/') OR (substr($url, -1) == '\\') ){

$url = substr($url, 0, -1);
}

$url .= '/index.php';
header("Location: $url");
exit();

} else { 
$_SESSION = array();
session_destroy();
setcookie ('PHPSESSID'. '', time()-300, '/', '', 0);
}

$page_title ='logged out!';

echo ' you are now logged out';

Link to comment
https://forums.phpfreaks.com/topic/215007-setcookie-expects-paramater-to-be-long/
Share on other sites

I believe you want a comma instead of a period following the first parameter.

Instead of

<?php
setcookie ('PHPSESSID'. '', time()-300, '/', '', 0);
?>

do

<?php
setcookie ('PHPSESSID', '', time()-300, '/', '', 0);
?>

 

Ken

That's what I was missing. The coma/period. But now I'm curious about whether or not I need to set that cookie. I'm following a tutorial that had it in the code. Is it not necessary? I thought it was there in case I sign out, but don't close the window or something like that.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.