function getUserID($db) { if (!is_object($db)) { return FALSE; } if (!($db instanceof mysqli)) { return FALSE; } if (!isset($_COOKIE['userid'], $_COOKIE['password'])) { return FALSE; } $sql = 'SELECT userid FROM user WHERE userid = ? AND password = ?'; $stmt = $db->prepare($sql); if (!$stmt) { return $db->error; } $stmt->bind_param('is', $_COOKIE['userid'], $_COOKIE['password'] ); if ($stmt->execute()) { $str = $stmt->error; $stmt->close(); return $str; } $stmt->bind_result($userid); if (!$stmt-fetch()) { $stmt->close(); return FALSE; } $stmt->close(); return $userid; }
<?php error_reporting(E_ALL); ini_set('display_errors', 1); include 'inc/constants.php'; include 'inc/variables.php'; include 'inc/functions.php'; include 'config/db_open.php'; $ret = 1; /* $ret contains the 'return'-result from include. * The files for include are defined in inc/variables.php */ /* check if there has been sent anything with $_GET, * otherwise load 'news' by default */ /* Include-files must have a return argument with one of the following * contents: * * -normal execution * Array('filename' => string, -- filename of the template-file *.tpl * 'data' => Array()) -- array containing data for the template * * When error occurs * string -- contains error message that should be displayed * */ /* Check if the user has coockies for login */ // $coockie_check = include 'user/loggedin.php'; if (isset($_GET['section'], $datafile[$_GET['section']])) { if (file_exists($datafile[$_GET['section']])) { $ret = include $datafile[$_GET['section']]; } else { $ret = "Fejl: Fil kunne ikke indlæses. Filnavn: ".$datafile[$_GET['section']]; } } else { $ret = include $datafile['pm']; /* Manual setting of section - default = news */ } /* include doctype, <html> and the complete head element */ readfile('htmlfile/header.html'); /* check if the array contains any useful values */ if (is_array($ret) and isset($ret['filename'], $ret['data']) and is_string($ret['filename']) and is_array($ret['data'])) { if (file_exists($file = $ret['filename'])) { /* saves the template into a variable which can be used here */ $data = $ret['data']; include $file; } else { /* File not found - display error message */ $data = array(); $data['msg'] = 'Fejl: Template "'.$ret['filename'].'" blev ikke fundet.'; include 'template/error.tpl'; } } elseif (is_string($ret)) { /* Include returned a string - that means an error occurred. * Display the errormessage */ $data = array(); $data['msg'] = $ret; include 'template/error.tpl'; } elseif ( 1 === $ret) { /* nothing returned*/ $data['msg'] = 'Fejl: Include-filen har ikke returneret noget (glemt return?).'; include 'template/error.tpl'; } /* include footer (including closing </div> for container */ readfile('htmlfile/footer.html'); ?>
<?php if (!$userid = getUserID($db)) { return NOT_LOGGED_IN; } /* possible actions */ $actions = array(); $actions['view'] = 'pm_view.php'; $actions['delete'] = 'pm_delete.php'; $actions['reply'] = 'pm_reply.php'; $actions['find'] = 'pm_find.php'; $actions['new'] = 'pm_new.php'; if (isset($_GET['action'], $actions[$_GET['action']])) { return include $actions[$_GET['action']]; } /* nothing chosen, return overview */ return include 'pmmsgsys/pm_overview.php'; ?>
<?php error_reporting(E_ALL); ini_set('display_errors', 1); include 'inc/constants.php'; include 'inc/variables.php'; include 'inc/functions.php'; include 'config/db_open.php'; $ret = 1; /* $ret contains the 'return'-result from include. * The files for include are defined in inc/variables.php */ /* check if there has been sent anything with $_GET, * otherwise load 'news' by default */ /* Include-files must have a return argument with one of the following * contents: * * -normal execution * Array('filename' => string, -- filename of the template-file *.tpl * 'data' => Array()) -- array containing data for the template * * When error occurs * string -- contains error message that should be displayed * */ /* Check if the user has coockies for login */ var_dump($_COOKIE['userid']); // Her viser cookien = 3 if (isset($_GET['section'], $datafile[$_GET['section']])) { if (file_exists($datafile[$_GET['section']])) { $ret = include $datafile[$_GET['section']]; } else { $ret = "Fejl: Fil kunne ikke indlæses. Filnavn: ".$datafile[$_GET['section']]; } }
function getUserID($db) { if (!is_object($db)) { return FALSE; } if (!($db instanceof mysqli)) { return FALSE; } // var_dump ($_COOKIE['userid']); // Her vises 33 if (!isset($_COOKIE['userid'], $_COOKIE['password'])) { return FALSE; }