Results 1 to 1 of 1
I'm using php 4.3.
I'm using sessions for my login and logout. The problem i have is that when I login on the same pc using different accounts its fine. ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 09-24-2003 #1Just Joined!
- Join Date
- Sep 2003
- Posts
- 27
Sessions help
I'm using php 4.3.
I'm using sessions for my login and logout. The problem i have is that when I login on the same pc using different accounts its fine. The problem is when I logout one account, ALL session variables are destroyed so my other window with the other account running cannot continue. Can someone help?
part of my login codemy logout codeCode:if($user=='admin'){ //Connecting to the MySQL server as root and selecting the database $connection=mysql_connect("localhost", "admin") or die ("Error ocurred when connecting to mysql server."); mysql_select_db("project") or die ("Error ocurred when selecting database."); $sql = mysql_query("SELECT Password,Login FROM admin WHERE Userid='$userid'"); $fetch_em = mysql_fetch_array($sql); $numrows = mysql_num_rows($sql); if($fetch_em["Login"] == "Y") { include 'Project.html'; echo "<font color=red>You have already logged in at another location!</font>"; exit(); } else { // Convert password to md5 hash $password = md5($password); if($numrows != "0" &($password == $fetch_em["Password"])){ $sql_get_index = mysql_query("SELECT ID FROM admin WHERE Userid='$userid'"); $fetch_index = mysql_fetch_array($sql_get_index); $sql_login = mysql_query("UPDATE admin SET Login='Y' WHERE Userid='$userid'"); mysql_close(); session_start(); // Start Session $_SESSION['ID'] = "A".$fetch_index["ID"]; header("Location: Padmin.php"); exit(); }elseif($numrows == "0"){ require 'Project.html'; echo "<font color=red>There is no such ID!</font>"; exit(); }else{ include 'Project.html'; echo "<font color=red>You have entered an invalid password!</font>"; exit(); } }Code:<?php session_start(); $index = substr($_SESSION['ID'], 1); $AC = substr($_SESSION['ID'], 0, 1); //Connecting to the MySQL server as root and selecting the database $connection = mysql_connect("localhost", "root") or die ("Error ocurred when connecting to mysql server."); mysql_select_db("project") or die ("Error ocurred when selecting database."); if($AC == "A") { $sql_status = mysql_query("SELECT Login FROM admin WHERE ID='$index'"); $status = mysql_fetch_row($sql_status); } elseif($AC == "C") { $sql_status = mysql_query("SELECT Login FROM customer WHERE ID='$index'"); $status = mysql_fetch_row($sql_status); } //if($status[0] == 'N') if(!isset($_SESSION['ID'])) { ?> Session over! To try logging in again, click here. <?php exit; } if(!isset($_REQUEST['logmeout'])){ echo "<center><font size=5>GLORY GLORY TOTTENHAM HOTSPUR</font></center> "; echo "<center><font color=red>Are you sure you want to logout?</font></center> "; echo "<center>No"; echo " <center><font color=orange>Keller King Richards Gardner Carr Ziege Redknapp Davies Ricketts Kanoute Keane Sullivan Taricco Perry Anderton Acimovic Blondel Dalmat Konchelsky Marney Postiga Zamora</font></center>"; } else { if($AC == "A") { $sql_logout = mysql_query("UPDATE admin SET Login='N' WHERE ID='$index'"); } elseif($AC == "C") { $sql_logout = mysql_query("UPDATE customer SET Login='N' WHERE ID='$index'"); } mysql_close($connection); unset($_SESSION['ID']); $_SESSION = array(); session_destroy(); header("Location: Project.html"); } ?>


Reply With Quote
