I have a logout button and when i clicked i want it to go to the home screen that has only the login form. Imagine it is like a pc that when you choose to log out it closes the session, saves the work and then go to the login screen.

The logout button

 <div id="Logout">
    <a href="logout.php" id="LogoutAction"><img src="https://cdn2.iconfinder.com/data/icons/crystalproject/crystal_project_256x256/apps/exit.png"></a>

The login form without css:

<div id="Login">       
        <label for="username">Username:</label>
        <input type="text" id="username" name="username">
        <label for="password">Password:</label>
        <input type="password" id="password" name="password">
        <div id="lower">
        <input type="submit" value="Login">
        </div><!--/ lower-->

I want to go to the login screen when the button is clicked

2 Answers

Arnaud Brenier On

You have to destroy the session then make a redirection :

header('Location: login.php');


Marco Sanchez On

Your href in the <a> tag will only work if logout.php is in the same dir

Try the following:

<!-- if logout.php is in the root dir-->    
<a href="/logout.php" id="LogoutAction">

<!-- if logout.php is in another dir -->    
<a href="/anotherDir/logout.php" id="LogoutAction">

<!-- if logout.php is in the upper dir -->    
<a href="../logout.php" id="LogoutAction">

<!-- if logout.php is in a child dir -->    
<a href="./childDir/logout.php" id="LogoutAction">