/
limbo_login_tools.php
58 lines (44 loc) · 1.4 KB
/
limbo_login_tools.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<!--
This file contains PHP login helper functions.
Orginally created by Ron Coleman.
And has been Adapted by Antonio delveccio and Leo Keefe
-->
<?php
# Includes these helper functions
require( 'includes/helpers.php' ) ;
# Loads a specified or default URL.
function load( $page = 'linkypresidents.php', $pid = -1 )
{
# Begin URL with protocol, domain, and current directory.
$url = 'http://' . $_SERVER[ 'HTTP_HOST' ] . dirname( $_SERVER[ 'PHP_SELF' ] ) ;
# Remove trailing slashes then append page name to URL and the president id.
$url = rtrim( $url, '/\\' ) ;
$url .= '/' . $page . '?id=' . $pid;
# Execute redirect then quit.
session_start( );
header( "Location: $url" ) ;
exit() ;
}
# Validates the president name.
# Returns -1 if validate fails, and >= 0 if it succeeds
# which is the primary key id.
function validate($lname = '')
{
global $dbc;
if(empty($lname))
return -1 ;
# Make the query
$query = "SELECT id, lname FROM presidents WHERE lname='" . $lname . "'" ;
show_query($query) ;
# Execute the query
$results = mysqli_query( $dbc, $query ) ;
check_results($results);
# If we get no rows, the login failed
if (mysqli_num_rows( $results ) == 0 )
return -1 ;
# We have at least one row, so get the frist one and return it
$row = mysqli_fetch_array($results, MYSQLI_ASSOC) ;
$pid = $row [ 'id' ] ;
return intval($pid) ;
}
?>