Question

I've got a weird problem. I created a application in PHP JS etc. And everything was fine. All headers were working fine too. But today I just want to check my website and it just stopped working.

Just like this code:

<body>
<?php
session_start();
session_destroy();
header("Location: index.php?error=logout");
exit;
?>
</body> 

I don't see there any output, any echos. But it still doesn't work.

Can someone tell me what's wrong? Maybe something has changed in PHP specification without my mind?

I just edited it to:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Voter</title>

<link rel="Stylesheet" type="text/css" href="style.css" />

</head>

<?php
session_start();
session_destroy();
header("Location: index.php?error=logout");
?>
</html>

That's the full code of the website.

When I just deleted all other code, like this:

<?php
session_start();
session_destroy();
header("Location: index.php?error=logout");
?>

It works fine. But why it was working before, and now i had to change it?

Was it helpful?

Solution

Try this:

<?php
session_start();
session_destroy();
header("Location: /index.php?error=logout");
?>

OTHER TIPS

Header only works if it no other text has been printed.

So, the header command must come before the

<head>

So for example,

<?php
session_start();
session_destroy();
header("Location: index.php?error=logout");
exit;
?>
<body>
</body> 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top