Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

logout function - help with explanations

Explorer ,
Apr 17, 2010 Apr 17, 2010

Hey all,

I was trying to learn how to do a logout function (not just have dreamweaver do it for me).  I got the code to work, but I don't completely understand what it's doing.  I've got it set up as follows:

The link the user sees is the following:

<li><a href="logout.php">Log Out</a></li>

The logout page is build as follows:

<?php
//start the session
session_start();


session_unset();
session_destroy();
header( "Location: ../index.php" );

?>

OK, so now with this working and it redirecting the user to the correct page, the many tutorials and books I used to try and learn this didn't do a good job explaining what this is doing (just what to do).  So, my question is, since I don't see any reference to the session that is open when the user is logged in on the logout page, how does this page know what session to destroy?  For example, when I tested this I was logged into this page and the Adobe site, this logout page only logged me out of the site it was in, and not the Adobe site.  How does this know that it was that session to end and not the Adobe session?

Also, the last line   header("Location: ../index.php");  is a line that I've never seen before.  I know this is a redirect line, but why does it use "header" in the beginning of the line?

Thank you very much for your help.

TOPICS
Server side applications
456
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 21, 2010 Apr 21, 2010
LATEST

Sessions are maintained on the server and controlled via server side scripting. Your code is executing on your server, so it has no impact on other sessions that you may have also established on other servers.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines