1. Trang chủ
  2. » Công Nghệ Thông Tin

Secure PHP Development- P39 pptx

5 315 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Central User Management System
Trường học Standard University
Chuyên ngành Computer Science
Thể loại Thesis
Năm xuất bản 2003
Thành phố New York
Định dạng
Số trang 5
Dung lượng 74,52 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Trang 1

class User {

function User($dbi = null, $uid = null) {

global $AUTH_DB_TBL,

$MIN_USERNAME_SIZE,

$MIN_PASSWORD_SIZE,

$ACTIVITY_LOG_TBL;

$this->user_tbl = $AUTH_DB_TBL;

$this->user_activity_log = $ACTIVITY_LOG_TBL;

$this->dbi = $dbi;

//print_r($this->dbi);

$this->minmum_username_size = $MIN_USERNAME_SIZE;

$this->minmum_pasword_size = $MIN_PASSWORD_SIZE;

$this->USER_ID = $uid;

//$this->debugger = $debugger;

$this->user_tbl_fields = array(‘EMAIL’ => ‘text’,

‘PASSWORD’ => ‘text’,

‘TYPE’ => ‘number’,

‘ACTIVE’ => ‘number’

);

if (isset($this->USER_ID)) {

$this->is_user = $this->getUserInfo();

} else {

$this->is_user = FALSE;

} }

Continued

Trang 2

Listing 6-1 (Continued)

function isUser() {

return $this->is_user;

}

function getUserID() {

return $this->USER_ID;

}

function setUserID($uid = null) {

if (! empty($uid)) {

$this->USER_ID = $uid;

}

return $this->USER_ID;

}

function getUserIDByName($name = null) {

if (! $name ) return null;

$stmt = “SELECT USER_ID FROM $this->user_tbl WHERE EMAIL = ‘$name’”;

$result = $this->dbi->query($stmt);

if ($result != null) {

$row = $result->fetchRow();

return $row->USER_ID;

}

return null;

}

function getUserTypeList() {

global $USER_TYPE;

Trang 3

function getUID() {

return (isset($this->USER_ID)) ? $this->USER_ID : NULL;

}

function getEMAIL() {

return (isset($this->EMAIL)) ? $this->EMAIL : NULL;

}

function getPASSWORD() {

return (isset($this->PASSWORD)) ? $this->PASSWORD : NULL;

}

function getACTIVE() {

return (isset($this->ACTIVE)) ? $this->ACTIVE : NULL;

}

function getTYPE() {

return (isset($this->TYPE)) ? $this->TYPE : NULL;

}

function getUserFieldList() {

return array(‘USER_ID’, ‘EMAIL’, ‘PASSWORD’, ‘ACTIVE’, ‘TYPE’);

}

function getUserInfo($uid = null) {

$fields = $this->getUserFieldList();

$fieldStr = implode(‘,’, $fields);

$this->setUserID($uid);

$stmt = “SELECT $fieldStr FROM $this->user_tbl “

“WHERE USER_ID = $this->USER_ID”;

//echo “$stmt <P>”;

Continued

Trang 4

Listing 6-1 (Continued)

$result = $this->dbi->query($stmt);

if ($result->numRows() > 0) {

$row = $result->fetchRow();

foreach($fields as $f) {

$this->$f = $row->$f;

}

return TRUE;

}

return FALSE;

}

function getUserIDbyEmail($email = null) // needed for EIS {

$stmt = “SELECT USER_ID FROM $this->user_tbl “

“WHERE EMAIL = ‘$email’”;

$result = $this->dbi->query($stmt);

if($result->numRows() > 0) {

$row = $result->fetchRow();

return $row->USER_ID;

} else {

return 0;

} }

function getUserList() {

Trang 5

$result = $this->dbi->query($stmt);

$retArray = array();

if ($result != null) {

while($row = $result->fetchRow()) {

$retArray[$row->USER_ID] = $row->EMAIL;

} }

return $retArray;

}

function makeUpdateKeyValuePairs($fields = null, $data = null) {

$setValues = array();

while(list($k, $v) = each($fields)) {

if (isset($data[$k])) {

//echo “DATA $k = $data[$k] <br>”;

if (! strcmp($v, ‘text’)) {

$v = $this->dbi->quote(addslashes($data[$k]));

$setValues[] = “$k = $v”;

} else {

$setValues[] = “$k = $data[$k]”;

} } }

Continued

Ngày đăng: 07/07/2014, 07:20