Jump to content

session_end and header() issue


EmperorJazzy

Recommended Posts

Afternoon all,

 

Quick query;

 

On the index.php page I have a hyperlink entitled LOGOUT. This allows the users to log out of their current session.

 

The hyperlink directs to a logout.php page with the following contents:

 

<?php
session_end();
?>
<html>
<head></head>
<body>
<?php
header('Location: index.php');
?>
</body>
</html>

 

Essentially; the code should end the session and redirect the browser back to the main page. Currently, the hyperlink does redirect to the logout.php page, but;

 

- it doesn't return to the index.php page

- if I click the back button, the session is still alive

 

Can anyone assist? Is there a better way of doing this?

 

This isn't something that hasn't been done before, but finding the topic in the forums has been difficult.

 

Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/232347-session_end-and-header-issue/
Share on other sites

What are you using to write your code? I just solved the same issue in one of my scripts. It was caused by a BOM (Byte Order Mark) which is an invisible line of code before the initial <?php. PHP will know it's there and process it, which will cause header errors.

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.