|
|
|
ในหน้าเว็บเดียวกันเวลาล็อคอินให้มันเด้งมาหน้าเดิมและเปลี่ยนจากปุ่มล็อคอินเป็นชื่อผู้ใช้ทำอย่างไรครับ |
|
|
|
|
|
|
|
ใช้ได้หาลยวิธี อาจจะเป็น SESSION หรือ COOKIE ก็ได้
เช่น
Code (PHP)
<?php
if($_SESSION['username']=="" && $_SESSION['password']==""){
?>
<form action="">
Login form
</form>
<?php
}else{
?>
Detail user
<?php
}
?>
|
|
|
|
|
Date :
2013-12-08 10:22:55 |
By :
Krungsri |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ไมได้อะครับ ผมใส่เป็นแบบนี้นะ
Code (PHP)
<?php
if($_SESSION['user']=="" && $_SESSION['pass']==""){
?>
<form id="form1" name="form1" method="POST" action="<?php echo $loginFormAction; ?>">
user
<label for="user"></label>
<input type="text" name="user" id="user" />
pass
<label for="pass"></label>
<input type="password" name="pass" id="pass" />
<input type="submit" name="submit" id="submit" value="Submit" />
</form>
<?php
}else{
?>
Detail user
<?php
}
?>
พอแสดงผลยังเหมือนเดิมไม่มีอะไรเปลี่ยนแปลง
|
|
|
|
|
Date :
2013-12-08 10:37:32 |
By :
pud |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code login ได้ใช้ SESSION ป่าวคับ
|
|
|
|
|
Date :
2013-12-08 11:28:47 |
By :
Krungsri |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ผมใช้ dreamweaver ทำโค๊ดเป็นอย่างงี้ครับ
Code (PHP)
<?php require_once('Connections/test.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'])) {
$loginUsername=$_POST['user'];
$password=$_POST['pass'];
$MM_fldUserAuthorization = "";
$MM_redirectLoginSuccess = "member.php";
$MM_redirectLoginFailed = "index.php";
$MM_redirecttoReferrer = false;
mysql_select_db($database_test, $test);
$LoginRS__query=sprintf("SELECT id, pass FROM member WHERE id=%s AND pass=%s",
GetSQLValueString($loginUsername, "int"), GetSQLValueString($password, "text"));
$LoginRS = mysql_query($LoginRS__query, $test) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
$loginStrGroup = "";
if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
//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 );
}
}
?>
|
|
|
|
|
Date :
2013-12-08 14:02:03 |
By :
pud |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<?php
if($_SESSION['MM_Username']=="" && $_SESSION['MM_UserGroup']==""){
?>
<form id="form1" name="form1" method="POST" action="<?php echo $loginFormAction; ?>">
user
<label for="user"></label>
<input type="text" name="user" id="user" />
pass
<label for="pass"></label>
<input type="password" name="pass" id="pass" />
<input type="submit" name="submit" id="submit" value="Submit" />
</form>
<?php
}else{
?>
Detail user
<?php
}
?>
|
|
|
|
|
Date :
2013-12-08 14:04:27 |
By :
Krungsri |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|