Can anyone help me around for login session not working

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

ashiqueali
New php-forum User
New php-forum User
Posts: 1
Joined: Sun Mar 30, 2014 11:19 pm

Can anyone help me around for login session not working

Postby ashiqueali » Sun Mar 30, 2014 11:36 pm

I am new in php, i need to logged in with different user in a project but its now working ... once i logout and go back to the browser then the previous user window will open .

index.php code

Code: Select all

<?php

      if (isset($_POST['submit'])) {
         $username = $_POST['username'];
         $password = $_POST['password'];
         
            if (empty($username) or empty($password)) {
               $message = "You can't leave empty fields";
            }
            else {
               
               $sql = mysql_query("SELECT * FROM `department` WHERE username='".$username."' AND password='".$password."'");
               
               $login_check = mysql_num_rows($sql);
               if($login_check > 0){
                  while($row = mysql_fetch_array($sql)){
                     // Get member ID into a session variable
                     $id = $row["ID"];   
                     
                     $_SESSION['ID'] = $id;
                     // Get member username into a session variable
                     $username = $row["username"];   
                     
                     $_SESSION['username'] = $username;
                     // Update last_log_date field for this member now
                     //mysql_query("UPDATE members SET lastlogin=now() WHERE id='$id'");
                     // Print success message here if all went well then exit the script
                     header("location: division.php?ID=$id");
                     exit();
                  } // close while
               }
                           }
                     }
      
   ?>


department.php

Code: Select all

<?php
session_start();
$_SESSION["ID"];
$_SESSION["username"];


if (isset($_SESSION['ID'])) {
   // Put stored session variables into local php variable
    $userid = $_SESSION['ID'];
    $username = $_SESSION['username'];
   $id=$_GET['ID'];
}
?>
<?php

$id = $_GET['ID'];
if ($id == "") {
   echo "Missing Data to Run";
   exit();
}

include_once "php/connect.php";

$sql = mysql_query("SELECT * FROM department WHERE ID='$id' LIMIT 1");
$count = mysql_num_rows($sql);
if ($count > 1) {
   echo "There is no user with that id here.";
   exit();   
}
while($row = mysql_fetch_array($sql)){
   $id=$row['ID'];
$department = $row["Department"];
$name= $row["name"];
}
?>



logout.php

Code: Select all

session_destroy();
header('location:../index.php') ;

Return to “PHP coding => General”

Who is online

Users browsing this forum: Bing [Bot], krotbacca and 2 guests