Log in log out session php

2015-10-21T19:27:29

I have here the code of my login and logout can you guys check if the session I placed is correct?

Login code:

<?php
session_start();

header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header('Content-Type: text/html');

$connection = mysql_connect("localhost", "root", "");
$db = mysql_select_db("store_data", $connection);

if(isset($_POST['login'])){
    $admin=$_POST['user'];
    $pass=$_POST['pass'];
    $select_user = mysql_query("SELECT admin_name FROM admin");
    $select_pass = mysql_query("SELECT admin_pass FROM admin");
    $result_1 = mysql_fetch_assoc($select_user);
    $result_2 = mysql_fetch_assoc($select_pass);

    if($admin !=$result_1['admin_name'] || $pass!=$result_2['admin_pass']){
        echo "<script >alert('Invalid password or username')</script>";
        header("refresh:0; url=administrator.php" );
    }

Logout code:

<?php

session_destroy();
header("Location: administrator.php");

?>

Copyright License:
Author:「drandreb andal」,Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.
Link to:https://stackoverflow.com/questions/33258130/log-in-log-out-session-php

About “Log in log out session php” questions

Everything works fine like the Log in and then that changing to a page and saying you are logged in and i can straight away move on with my work but now if i want to Log out and click Log out, it d...
When a user is logged in, I want them to have a button to log out and be redirected to the page they are on, however, with a few additional features, which are called. Unfortunately, nothing happen...
I'm currently working on a site that has a log-in (username and password) - The password protection is done by the operating system within the web server at folder level called a Realm within the O...
My PHP Sessions are giving me yet another headache. I have just created a log-out page in my PHP code. when the user clicks on the link, he is logged out of the system. I got my code from severa...
This is the code i have at the moment but will not work, displays log out button when logged in only on one page then logs user out automatically ? &lt;?php if(!session_is_registered(myusername))...
Login Function: // Create User Session Variable session_start(); $_SESSION['session_id'] = $session_id; Logout Function: // Clear Session Variable session_start(); unset ($_SESSION["session_id"
Here is the code I'm using to log in a user : if($username==$db_username&amp;&amp;$password==$db_password) { session_start(); echo 1; header("Location: index2.php"...
When I try to log out the session is destroyed but I still can go inside that page and view details without logging in first by using the Mozilla browser back button or history cache. code for log...
I have problems with the log out system on my PHP page. When I try to log a second out, after logging out the first one, it displays me session details of the first accout. So the problem is the
The below code expires a page only on manual page refresh. I want the page to automatically expire the session and log out the user and redirect to the login page. &lt;?php session_start(); if( ...

Copyright License:Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.