0

I was making a library system that if you logged in you will be redirected to the customer information.

<?php 

include('session.php');
include('dbcon.php');?>

<html>
<head>
    <title>Library</title>
    <style type="text/css">
    <!--
    body,td,th {
        font-family: Arimo, sans-serif;
    }
    body {
        background-image: url(image/bg9.jpeg);
        background-repeat: repeat;
    }
    .style72 {
        font-size: 14;
        color: red;
        font-weight: light;
    }
    -->
    </style>
</head>
<body>
    <p align="center"><img src="image/logo.png" width="133" height="151"></p>
    <br/>
    <?php include('header.php'); ?>
    <?php include('head.php'); ?>           
    <br/><br/>  
    <table width="945" height="33" align="center">
        <tr>
            <td width="47" height="27">
                <div align="center">
                    <a href="index.php"><img src="image/homeicon.png" width="34" height="35" border="0" /></a>
                </div>
            </td>
            <td width="137">
                <div align="center" class="style72">
                    <a href="member.php">PROFILE</a>
                </div>
            </td>
            <td width="137">
                <div align="center" class="style72">
                    <a href="contactus.php">CONTACT US</a>
                </div>
            </td>
            <td width="117">
                <div align="center" class="style72">
                    <a href="faq.php">FAQs</a>
                </div>
            </td>
            <td width="123">&nbsp;</td>            
            <td width="123">&nbsp;</td>
            <td width="23">&nbsp;</td>
            <td width="126">
                <div align="center" class="style72">
                    <a href="logout.php">LOGOUT</a>
                </div>
            </td>
        </tr>
    </table>
</body>
</html>

This is my session.php

<?php
// Establishing Connection with Server by passing server_name, user_id and password as a parameter
$connection = mysql_connect("localhost", "root", "");

// Selecting Database
$db = mysql_select_db("librarian", $connection);
session_start();// Starting Session

// Storing Session
$member_check=$_SESSION['member'];

// SQL Query To Fetch Complete Information Of User
$ses_sql=mysql_query("select member_name from member where member_name='$member_check'", $connection);

$row = mysql_fetch_assoc($ses_sql);
$member_session = $row['member_name'];
if(!isset($member_session)){
    mysql_close($connection); // Closing Connection
    header('Location: index.php'); // Redirecting To Home Page
}
?>

I really do not know what is the problem here. I have already clear my cookies and history. But cannot run also have error. I am sorry, I don't know how to code php well. Anyone can help me? This is my project final.

Kevin Stich
  • 773
  • 1
  • 8
  • 24
shby
  • 1
  • 4
  • Please update to the new MySQL driver - mysqli. [See here.](http://stackoverflow.com/questions/548986/mysql-vs-mysqli-when-using-php) It's deprecated in PHP 5.5 and removed in 7.0 – Kevin Stich Dec 13 '16 at 06:54

1 Answers1

0

In this answer I'm trying to point out errors in your code

I think data is not coming from the database , so the !isset() become true and it redirects to the index.php, but the session is already set . So you again come back to this page , again , no data from the database make you end up in a loop hence too many redirects.

You have to put session_start() on the top in the php tag

And use mysqli instead of mysql

Include dbcon.php before the session.php

Unset the session variable after you used it.

this step by step article will help you to make a good login system, with increased security and all .

lasan
  • 199
  • 1
  • 13