Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- global $my_var;
- // login_functions.php
- require('./db_data.php');
- session_start();
- function isLoggedIn() {
- if (!isset($_SESSION['email'])) {
- return FALSE;
- }
- else {
- global $my_var;
- $my_var = 'Logado como <i>' . $_SESSION['email'] .
- '</i>.' . ' <a href="?logout">Sair do site.</a></p>';
- return TRUE;
- }
- }
- function logUserIn() {
- include('./formlogin.html.php');
- db_connect(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DBNAME) or
- die('Erro ao conectar com a base de dados.');
- /* Import $db_con from the function called above. */
- global $db_con;
- if (!empty($_POST['email']) && !empty($_POST['password'])) {
- $email = mysqli_real_escape_string($db_con, $_POST['email']);
- //var_dump($email);
- $password = mysqli_real_escape_string($db_con, md5($_POST['password']));
- //var_dump($password);
- $resutl_set = mysqli_query($db_con, "SELECT * FROM TBL_romario_admin
- WHERE email='$email' AND password='$password'");
- if (mysqli_num_rows($resutl_set) <= 0) {
- $error = 'Login inválido.';
- include('./error.html.php');
- exit();
- }
- if (mysqli_num_rows($resutl_set) == 1) {
- $found_this_user = mysqli_fetch_array($resutl_set);
- $_SESSION['email'] = $found_this_user['email'];
- }
- /* Don't put header('Location: ./') in the index.php. */
- header('Location: ./');
- }
- return TRUE;
- }
- require_once('./db_data.php');
- /**
- * This function attempts to connect to a database, set the connecton encoding,
- * and select the database on the server. You must pass it the parameters:
- * 1. hostname - the hostname of the server.
- * 2. username - the user login on the server.
- * 3. password - the user password for the server.
- * 4. db_name - the database name to be used.
- **/
- function db_connect($db_hostname, $db_username, $db_password, $db_dbname) {
- /* To make $db_con available in the main script, since this is
- * a include file, and, by default $db_con would only be available
- * here, inside this function. */
- global $db_con;
- //$db_con = mysqli_connect('localhost', 'nando', 'senHa010');
- $db_con = mysqli_connect($db_hostname, $db_username, $db_password);
- if (!$db_con) {
- $error = 'Não foi possível conectar a base de dados.';
- include('./error.html.php');
- exit();
- }
- if (!mysqli_set_charset($db_con, 'utf8')) {
- $error = 'Não foi possíel estabelecer o encoding da conexão.';
- include('./error.html.php');
- exit();
- }
- if (!mysqli_select_db($db_con, $db_dbname)) {
- $error = 'Impossível localizar database.';
- include('./error.html.php');
- exit();
- }
- return TRUE;
- }
- function logUserOut() {
- unset($_SESSION['email']);
- header('Location: ./');
- }
- if (isset($_GET['logout'])) {
- logUserOut();
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement