Login, user rights, session ++

NorseMan

Member
I got an that was written about 2 years ago, a script I can't find out of now. I hope you can What's left of the script is just snippets, or what's left of the code blocks. I really hope someone can help me. It is login and rights that are mostly concerned. Below you will find a picture of the DB map, the SQL scripts to the MySQL database, PHP script fragments and a few of the script blocks on the sites header controlling the user rights. You will find this below.
What I want help with is to put this together again so the login works as it was and should.
The user rights are structured in three parts.

- Admin.
- Regular user (logged in).
- Not registered/logged in.

Finally, users who are not logged in are ordinary users who have the right to read some of the content on the pages, but are not allowed to edit their own saved data or access the member pages. Administrator has all rights and can do whatever he wants. Before then, this was controlled via code blocks in the header of each PHP page, and what each user is registered as.

- Before, the login was controlling the view of log in and log out button. They changed depending on whether you were logged in or not.

- On another site the members and their member data listed when you click the edit button beside the members name. All members in the list got this button beside their name, but when you are logged in all are neutral except the one belongs to the logged in person. When the admin is logged in all buttons should be activated.

- On another site that is a site for all. The visitors who are not logged in should see all the content on the site, but are you loged in you can click on your own item and read the information about them self. Admin got all rights and can edit, move and delete info. With other words do everything.

- The site also includes a signup and invoice part in the directory called invoice.

- The site also include a help button. Clicking this will open a information panel describing whats on the site entered. JavaScript controlling this is found in header.php . When the registration form is completed and I click send, all that is happening is a white site with the text ment to be sent to the DB is showing up. It should also send a PDF invoice to the registered email address from the form ment to be sent. I know that i nead to have the php send mail and configure this, but i dont remember how to to this. And how to get it/activate it.

The site is built up in 3 stages. header.php , content.php , footer.php
Before everything controlling the pages and user rights was in the header.php. I would like to have it it like that again. but i am unable to get it like that. The one who helped me with the PHP scripting is probably dead. I can do a little myself, but not too complicated. The script was all down, but I used a lot of time to recover it. The recovered script is what you are looking at here/below.

header.php

Code:
<?php
session_start();
$ROOT = str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']) . '/';
$HOST = 'http://' . $_SERVER['HTTP_HOST'] . '/';
$disabl1 = isset($_SESSION['member_id']) ? '' : 'w3-disabled'; 
$disabl2 = isset($_SESSION['member_id']) && isset($_SESSION['isadmin']) ? '' : 'w3-disabled';  
$log_btn = isset($_SESSION['member_id']) ?  'Logg ut' : 'Logg inn';
const SYSNAME = 'Management System';
const PAGETITLE = 'Velkommen';
const HELPBUTTON = "<span id='info_btn' class='w3-badge w3-small w3-white w3-border w3-border-white w3-right' title='Help'>?</span>";
?>
<!DOCTYPE html>
<html lang='no'>
<head>
<title><?=SYSNAME?></title>
<link rel="icon" type="image/x-icon" href="/images/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
<link rel='stylesheet' href='https://www.w3schools.com/w3css/4/w3.css'>
<link rel='stylesheet' href='css/main.css'>
<link rel='stylesheet' href='css/style.css'>
<link rel='stylesheet' href='css/footer.css'>
<link rel='stylesheet' href='css/footer_marina.css'>
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js'></script>
<script type='text/javascript'>
    $().ready(function() {
        $("#nav-marina").addClass("w3-bottombar")
        init()
        
        $("#info_btn").click( function() {
            $("#infopanel").toggle()
        })
    })
    
    function init()
    {
        $('.boat1').click(function() {
            var boat = $(this).data('id')
            $('.boat').css('fill', '#FCF8E8')
            $('.boat').attr('data-sel', 0)
            $(this).attr('data-sel', 1)
            $(this).parent().children().css('fill', '#FF0000')
            $.get(
                '',
                {'ajax':'getberth', 'boat':boat},
                function(resp) {
                    $('#query-results').html(resp)
                    $('#query-results').show()
                    location.href = '#query-results'
                },
                'TEXT'
            )
        })
        
        $('.berth').click( function() {
            var boat = $(".boat1[data-sel='1']")
            if (!boat) {
                return
            }
            else {
                var boatsize = $(boat).data('size')
                var berthsize = $(this).data('size')
                if (berthsize != boatsize) {
                    return
                }
                if ($(this).data('boat')) return;
                var boatid = $(boat).data('id')
                var berthid = $(this).data('bid')
                var date = $('#reberth_date').val()
                $.get(
                    '',
                    {'ajax':'reberth', 'boat':boatid, 'berth':berthid, 'date':date},
                    function(resp) {
                        $('.boat').attr('data-sel', 0)
                        $('#marina').html(resp)
                        init()
                    },
                    'TEXT'
                )
            }
        })
        
        $("#vortex").click( function() {
            var boat = $(".boat1[data-sel='1']")
            if (!boat) {
                return
            }
            var boatid = $(boat).data('id')
            var date = $('#reberth_date').val()
                $.get(
                    '',
                    {'ajax':'dispose', 'boat':boatid, 'date':date},
                    function(resp) {
                        $('.boat').attr('data-sel', 0)
                        $('#marina').html(resp)
                        init()
                    },
                    'TEXT'
                )
            
        })
        
    }
    function hideHelp() {
        $("#infopanel").toggle()
    }
    function hideInfo() {
        $('#query-results').hide()
        $('.boat').css('fill', '#FCF8E8')
        $('.boat').data('sel', 0)
    }
    
</script>

</head>
<body>
<header class='w3-container w3-blue-gray style=logo_box'>
<div class='text-align:right;'>
  <div class='div-table-col' align='left' width='82' height='78'><h4 class='inline'><a href="<?=$HOST?>index.php"><img src='<?=$HOST?>/images/w-logo-orange.png' border='0' width='82' height='78' alt='webmasterinfo logo'></a><?=SYSNAME?> - <?=PAGETITLE?> </h4></div>
  </div>
</header>
	<div class='w3-bar w3-light-gray w3-margin-bottom' style='height: 39px'>
	<a id='nav-members' href='<?=$HOST?>index.php' class='w3-bar-item w3-button'>Hjem</a>
	<a id='nav-register' href='<?=$HOST?>register.php' class='w3-bar-item w3-button'>Registrering</a>
    <a id='nav-members' href='<?=$HOST?>members.php' class='w3-bar-item w3-button'>Medlemmer</a>
    <a id='nav-marina' href='<?=$HOST?>marina.php' class='w3-bar-item w3-button'>Båtplass</a>
    <a id='nav-invoice'  href='<?=$HOST?>invoice/invoice.php' class='w3-bar-item w3-button'>Faktura</a>
	<a id='nav-login' href='<?=$HOST?>login.php' class='w3-bar-item w3-button w3-right'><?=$log_btn?></a>
</div>
<div style='display: inline-block; padding-top: 16px; font-size: 14pt; margin-right: 10px;' class='w3-right'></div>

member.php

This works, but there is something wrong in the block below so it dont show up. I can use the block from the marina.php (not described yet) to make it work, but there is a lot not working probably. Things like sort out member, admin and not registered user, and the help button etc. member.php session block below. So the blocks are different, but since one is working and one is not making me unsure who to use since they both contains missing parts.

Code:
<?php
session_start();
$ROOT = str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']) . '/';
$HOST = 'http://' . $_SERVER['HTTP_HOST'] . '/';
$disabl1 = isset($_SESSION['member_id']) ? '' : 'w3-disabled'; 
$disabl2 = isset($_SESSION['member_id']) && isset($_SESSION['isadmin']) ? '' : 'w3-disabled';  
$log_btn = isset($_SESSION['member_id']) ?  'Logg ut' : 'Logg inn';
const SYSNAME = 'Management System';
const PAGETITLE = 'Welcome';
const HELPBUTTON = "<span id='info_btn' class='w3-badge w3-small w3-white w3-border w3-border-white w3-right' title='Hjelp'>?</span>";
?>

marina.php

marina.php actually works as it should. The problem here is logging in. It seems like it doesn't understand who/what is logged in or out.

Code:
<?php
session_start();
include $ROOT.'db_inc.php';
$pdo = pdoConnect();
$ROOT = str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']) . '/';
$HOST = 'http://' . $_SERVER['HTTP_HOST'] . '/';
$loggedin =  $_SESSION['member_id'] ?? 0;
unset( $_SESSION['member_id'], $_SESSION['isadmin']);
if ($loggedin)  {
    header("Location: {$HOST}members.php");
    exit;
}

index.php - Does this nead a script block of the session to?

Code:
<?php
session_start();
$ROOT = str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']) . '/';
$HOST = 'http://' . $_SERVER['HTTP_HOST'] . '/';
$disabl1 = isset($_SESSION['member_id']) ? '' : 'w3-disabled'; 
$disabl2 = isset($_SESSION['member_id']) && isset($_SESSION['isadmin']) ? '' : 'w3-disabled';  
$log_btn = isset($_SESSION['member_id']) ?  'Logg ut' : 'Logg inn';
const SYSNAME = 'Management System';
const PAGETITLE = 'Velkommen';
const HELPBUTTON = "<span id='info_btn' class='w3-badge w3-small w3-white w3-border w3-border-white w3-right' title='Hjelp'>?</span>";
?>
<!DOCTYPE html>
<html lang='no'>
<head>
<title>Management System™</title>
<link rel="icon" type="image/x-icon" href="/images/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
<link rel='stylesheet' href='https://www.w3schools.com/w3css/4/w3.css'>
<link rel='stylesheet' href='css/main.css'>
	<link rel='stylesheet' href='css/colorbg.css'>
<link rel='stylesheet' href='css/footer.css'>
<link rel='stylesheet' href='css/footer_marina.css'>
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js'></script>
<script type='text/javascript'>
    function hideHelp() {
        $("#infopanel").toggle()
    }
    function hideInfo() {
        $('#query-results').hide()
        $('.boat').css('fill', '#FCF8E8')
        $('.boat').data('sel', 0)
    }
    
</script>

</head>
<body class="whitebg">
<?php include $ROOT.'header.php'?>
<?php include $ROOT.'front.php'?>
<?php include $ROOT.'footer.php' ?>
</body>	
</html>

Database graphic/map

DB_map.png


Some of the SQL neaded to understand this - member table


Code:
CREATE TABLE `member` (
  `member_id` int(11) NOT NULL,
  `fname` varchar(45) DEFAULT NULL,
  `lname` varchar(45) DEFAULT NULL,
  `member_class` int(11) DEFAULT NULL COMMENT '1 boating , 2- supporting',
  `address` varchar(100) DEFAULT NULL,
  `town` varchar(45) DEFAULT NULL,
  `county` varchar(45) DEFAULT NULL,
  `postcode` varchar(10) DEFAULT NULL,
  `email` varchar(45) DEFAULT NULL,
  `mobile` varchar(15) DEFAULT NULL,
  `extra` tinyint(4) DEFAULT NULL,
  `comments` varchar(255) DEFAULT NULL,
  `date_join` date DEFAULT NULL,
  `date_leave` date DEFAULT NULL,
  `password` varchar(100) DEFAULT NULL,
  `admin` tinyint(4) DEFAULT NULL COMMENT '1 = admin\n0 = ordinary member'
) ENGINE=InnoDB DEFAULT CHARSET=utf8 TABLESPACE `kjegri1_marina`;

Data sheet for table `member`


Code:
INSERT INTO `member` (`member_id`, `fname`, `lname`, `member_class`, `address`, `town`, `county`, `postcode`, `email`, `mobile`, `extra`, `comments`, `date_join`, `date_leave`, `password`, `admin`) VALUES
(12, 'Scott', 'Chegg', 1, NULL, NULL, NULL, NULL, 'Scott.Chegg@gmail.com', '07259049068', NULL, NULL, '2019-01-01', NULL, '$2y$10$KBlMC5wCL.K6EHvxSTIejOBBSRFesGhDfK.iNb7v.uexVwmQOhCPG', 1),
(13, 'Laura', 'Norder', 1, NULL, NULL, NULL, NULL, 'Laura.Norder@gmail.com', '07403996096', NULL, NULL, '2020-06-01', NULL, '$2y$10$KBlMC5wCL.K6EHvxSTIejOBBSRFesGhDfK.iNb7v.uexVwmQOhCPG', 0),
(14, 'Peter', 'Dowt', 1, '', '', '', '', 'Peter.Dowt@gmail.com', '07242833304', NULL, NULL, '2020-01-01', NULL, '$2y$10$KBlMC5wCL.K6EHvxSTIejOBBSRFesGhDfK.iNb7v.uexVwmQOhCPG', 0),
(15, 'Tom', 'DiCanari', 1, NULL, NULL, NULL, NULL, 'Tom.DiCanari@gmail.com', '07779956036', NULL, NULL, '2020-05-01', '2021-05-15', '$2y$10$KBlMC5wCL.K6EHvxSTIejOBBSRFesGhDfK.iNb7v.uexVwmQOhCPG', 0),
(16, 'Betty', 'Rubble', 2, NULL, NULL, NULL, NULL, 'Betty.Rubble@gmail.com', '07393502521', NULL, NULL, '2020-08-01', NULL, '$2y$10$KBlMC5wCL.K6EHvxSTIejOBBSRFesGhDfK.iNb7v.uexVwmQOhCPG', 0),
 
Back
Top