|
|
|
[แก้ได้แล้วค่ะ ][ขอคำแนะนำ $_SESSION ไม่ทำงาน] $_SESSION['username'] มันเช็คแค่ครั้งเดียวตอน login หน้าอื่นไม่เช็ค มีวิธีแก้ยังไงค่ะ |
|
|
|
|
|
|
|
ส่วนตรง header ที่โชว์ชื่อ เวลา login แล้วมันจะโชว์ชื่อให้ แต่พอกดไปหน้าอื่น $_SESSION['username'] ไม่ทำงาน ให้
แล้วตรงส่วนอื่นที่มีการใช้ $_SESSION['username'] จะไม่ทำงานเลย(ไม่สามารถดึงข้อมูลออกมาได้)
Code header.php
<?php
ob_start();
@session_start();
include'config/config.inc.php';
if(( $_POST['username']=="") || ($_POST['password']=="")){
} else {
$query = "SELECT * FROM member WHERE user='".strtolower($_POST['username'])."' AND password ='".$_POST['password']."'";
$result = mysql_query($query) or die (mysql_error());
if(mysql_num_rows($result) > 0 ){
$_SESSION['username'] = $_POST['username'];
}else{
$printchk = "<font color='#900' size='2'>ผู้ใช้งานหรือ รหัสผ่านไม่ถูกต้อง </font>";
}
}
?>
<?php
if($_SESSION['username']==""){
?>
<form action="" method="post">
<table style="width:65%; height:15px; padding:8px 5px ">
<tr >
<td style="width:20%; height:15px; padding:8px 5px;"><input type="text" name="username" class="form-control input-sm" placeholder="username" style="height:25px; width:146px; margin-left:25px; height:25px; padding:0 0 0 5px;"></td>
<td style="width:20%; height:15px; padding:8px 5px;"><input type="password" name="password" class="form-control input-sm" placeholder="password" style="height:25px; width:146px; margin-left:5px; height:25px; padding:0 0 0 5px;"></td>
<td style="width:10px; height:15px; padding:8px 5px""><input name="" type="submit" value="เข้าสู่ระบบ"></td>
<td colspan="2" align="right" width="10px" style=" height:15px; width:20px; padding:8px 5px""><?=$printchk?></td>
</tr>
</table>
</form>
<?php
}else {
$query = "select * from member where user='".$_SESSION['username']."'";
$result = mysql_query($query);
$rs = mysql_fetch_array($result);
?>
<tr height="28">
<td colspan="2" align="center" ><samp style='color: rgb(255,255,255); margin-left:15px; '>ยินดีต้อนรับ</samp></td>
</tr>
<tr height="1">
<td> </td>
</tr>
<tr height="20">
<td colspan="2" style="font-weight:bold;"> <samp style='color: rgb(255,255,255); '>คุณ <?=$rs[name]?></samp></td>
</tr>
<tr height="30" align="right">
<td colspan="2" style="font-size:13px; "><a href="./profile.php"><samp style='color: rgb(255,204,51); '>แก้ไขข้อมูลส่วนตัว</samp></a> <samp style='color: rgb(255,255,255); '>| </samp>
<a href="./logout.php"><samp style='color: rgb(255,204,51); '>ออกจากระบบ</samp></a> </td>
</tr>
<?Php } ?>
Tag : PHP, MySQL
|
ประวัติการแก้ไข 2014-03-12 19:00:54 2014-03-12 19:32:03 2014-03-12 19:59:25 2014-03-12 20:10:43 2014-03-13 10:25:36 2014-03-13 14:56:06
|
|
|
|
|
Date :
2014-03-12 19:00:21 |
By :
sama_9 |
View :
1027 |
Reply :
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
หน้าล็อกอินไม่ได้ start_session(); รึเปล่า?
|
|
|
|
|
Date :
2014-03-13 11:44:24 |
By :
{Cyberman} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
basic คือใส่ session_start(); ไว้ทุกหน้าเลยครับ เพื่อให้ session ยังคงอยู่
|
|
|
|
|
Date :
2014-03-13 11:46:39 |
By :
Ex-[S]i[L]e[N]t |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
กรณีอย่างนี้ แสดงว่าประกาศตัวแปรซ้ำกันคับ
|
|
|
|
|
Date :
2014-03-13 15:38:15 |
By :
Berbatov23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|