/    Sign up×
Community /Pin to ProfileBookmark

Why Logout function does not destroy Cookies?

I have code and would like to destroy cookies.

[code=php]
<?
session_start(); //starts the sessino that we have to remove

// call this page to all pages that need to be logged in to use.

//if they dont want to be remembered anymore we delete the cookies.

setcookie(“cookname”, “”, time()-60*60*24*100, “/”,”,0);
// setcookie(“cookpass”, “”, time()-60*60*24*100, “/”,”,0);

//and we destroy the session
session_destroy();

//either way, they are now logged out, so we will sent them away.
echo “<script language=’javascript’>
document.location=’index.php?message=?logout=done’;
</script>”;

?>

[/code]

to post a comment
PHP

9 Comments(s)

Copy linkTweet thisAlerts:
@bokehNov 04.2005 — [code=php]
<?
echo "<script language='javascript'>
document.location='index.php?message=?logout=done';
</script>";
?>[/code]
[/QUOTE]
What is that nonsense? You should be using something like:[code=php] header('Location: http://'.$_SERVER['HTTP_HOST'].str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']));[/code]
Copy linkTweet thisAlerts:
@ShrineDesignsNov 04.2005 — [code=php]<?php
session_start();
$_SESSION = array(); // destroys session vars
session_destroy();
header("Location : ./");
exit;
?>[/code]
Copy linkTweet thisAlerts:
@bokehNov 04.2005 — [code=php]header("Location : ./");[/code][/QUOTE][I]From php.net: [/I][B]Note:[/B] HTTP/1.1 requires an [B]absolute URI[/B] as argument to Location: including the scheme, hostname and absolute path, but some clients accept relative URIs.[/QUOTE]
Copy linkTweet thisAlerts:
@ShrineDesignsNov 04.2005 — i am aware of that[code=php]<?php
if($_SERVER['SERVER_PROTOCOL'] == 'HTTP/1.1')
{
$uri = 'http://' . $_SERVER['HTTP_HOST'] . str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']);
}
else
{
$uri = './';
}
header("Location: $uri");
exit;
?>[/code]
Copy linkTweet thisAlerts:
@bokehNov 04.2005 — i am aware of that[code=php]<?php
if($_SERVER['SERVER_PROTOCOL'] == 'HTTP/1.1')
{
$uri = 'http://' . $_SERVER['HTTP_HOST'] . str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']);
}
else
{
$uri = './';
}
header("Location: $uri");
exit;
?>[/code]
[/QUOTE]
Maybe I am misunderstanding but I thought that was for the client's benefit.
Copy linkTweet thisAlerts:
@toplisekauthorNov 05.2005 — I used JavaScript because I have error:

Warning: Cannot modify header information - headers already sent by (output started at ...:32) in ....php on line 26

I use this if I have error like that.

There should be no PHP Code before header('Location: index.php').

Do you know what I should check that header will work?

I have the following code on page:
[code=php]
<?php

if (isset($_POST['guest']))
{include("logout.php");
/*echo 'You are user as Guest. Please wait, you will be automatic redirected
to Start page.'; */

}
else {}
?>
[/code]


and logout page:
[code=php]


<?


session_start(); //starts teh sessino that we have to remove

$_SESSION = array(); // destroys session vars




//and we destroy the session

session_destroy();

//either way, they are now logged out, so we will sent them away.
header('Location: index.php');

exit;

?>




[/code]


?
Copy linkTweet thisAlerts:
@bokehNov 05.2005 — Warning: Cannot modify header information - headers already sent by (output started at ...:32) in ....php on line 26[/QUOTE]If you post an error message and want help with it, it would be very helpful if you posted the whole message without deleting parts. Also you should mark the respective lines in the script with their line numbers.

If you read the error messages careful you will find they tell you what the error is.
Copy linkTweet thisAlerts:
@toplisekauthorNov 05.2005 — hi Bokeh,

do not be angry.

Warning is this:

Warning: Cannot modify header information - headers already sent by (output started at...32) in ..logout.php on line 105

I would like to tell you the Line, but have problem, that this line is nonsense.

output started at ...:32) there is

<meta name="description" content="

...">

and on Line 105 there is:

header('Location: index.php');

I have problem with header a lot. There is no code before HEADER just

session_destroy();

I hope you can help to fix such problem. :rolleyes:
Copy linkTweet thisAlerts:
@bokehNov 05.2005 — You are like an old record stuck in the same groove asking the same questions once and again. [URL=http://www.webdeveloper.com/forum/showthread.php?t=80660&highlight=header]This is where you asked the same question last month![/URL] Maybe your brain is stuck in a loop!

Your script is written in a disordered way. The easiest way out for you without completely rewriting the script is just start the script with:[code=php]<?php
ob_start();[/code]
right at the very start before any output or whitespace.

Personally though I would write the script in the correct order:[code=php]<?php //line 1
if(this is a person I want to redirect){
header('Location: ...');
exit;
}
// Now continue with the script.[/code]
×

Success!

Help @toplisek spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...