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>
    </div>

The login form without css:

<div id="Login">       
        <form>
        <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-->
        </form>
    </div> 

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

2 Answers

-1
Arnaud Brenier On

You have to destroy the session then make a redirection :

header('Location: login.php');

https://www.php.net/manual/en/function.header.php

0
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">