|
|
|
รบกวนช่วยดูหน้า login ให้หน่อยครับ ผมจะทำหน้า login แบบแยกประเภทของ user น่ะครับ คือถ้าเป็นประเภท 0 ให้ไปหน้า user แต่ถ้าเป็นประเภท 1 ให้ไปหน้า admin |
|
|
|
|
|
|
|
ผมจะทำหน้า login แบบแยกประเภทของ user น่ะครับ คือถ้าเป็นประเภท 0 ให้ไปหน้า user แต่ถ้าเป็นประเภท 1 ให้ไปหน้า admin
แต่ผมไม่รู้ว่าต้องทำยังไงอะครับ
ทำได้แค่ให้ login ไปหน้าเดียวกันหมดเลย
รบกวนพี่ๆช่วยดูให้หน่อยนะครับ
ผมต้องการให้ไปเช็คจาก Field User_type ที่อยู่ใน table member อะครับ
Code (PHP)
?php require_once('Connections/Project.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
session_start();
}
$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
}
if (isset($_POST['User_name'])) {
$loginUsername=$_POST['User_name'];
$password=(md5($_POST['User_pass']));
$MM_fldUserAuthorization = "";
$MM_redirectLoginSuccess = "member/user.php";
$MM_redirectLoginFailed = "index.php";
$MM_redirecttoReferrer = false;
mysql_select_db($database_Project, $Project);
$LoginRS__query=sprintf("SELECT User_name, User_pass FROM member WHERE User_name=%s AND User_pass=%s",
GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
$LoginRS = mysql_query($LoginRS__query, $Project) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
$loginStrGroup == "";
//declare two session variables and assign them
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['MM_UserGroup'] = $loginStrGroup;
if (isset($_SESSION['PrevUrl']) && false) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
?>
Tag : PHP
|
|
|
|
|
|
Date :
2015-03-11 00:24:52 |
By :
teeratusz |
View :
678 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เลืกใช้ Tools อย่าง Dreamwaver ช่วย จะทำให้การเขียนโปรแกรม PHP/MySQL ไปได้เร็วยิ่งขึ้นครับ
|
|
|
|
|
Date :
2015-03-11 08:48:13 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54.$LoginRS__query=sprintf("SELECT User_name, User_pass FROM member WHERE User_name=%s AND User_pass=%s",
ตาราง member ควร มีฟีลด์ usertype เพื่อบอกว่าเป็น admin user หรือ อย่างอื่น
Code (PHP)
<?php
session_start();
// getlogin.php
$LoginRS__query=sprintf("SELECT * FROM member WHERE User_name=%s AND User_pass=%s",
GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
$LoginRS = mysql_query($LoginRS__query, $Project) or die(mysql_error());
if ( mysql_num_rows( $LoginRS) ) {
$_SESSION['MM_Profile']=mysql_fetch_assoc($LoginRS);
switch( $_SESSION['MM_Profile']['user_type']) {
case 'Admin':
case 'Staff':
case 'Member': $url=strtolower($_SESSION['MM_Profile']['user_type']); break;
default: $url='guest';
}
header("Location: ". $url . '.php' );
} else {
header("Location: ". $MM_redirectLoginFailed );
}
?>
////////////////////////////////////////////////////////////
<?php
session_start();
// other.php
if( !isset( $_SESSION['MM_Profile'] )) header( 'location: login.php' );
// do other job
?>
|
|
|
|
|
Date :
2015-03-11 08:50:47 |
By :
Chaidhanan |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|