Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,028

HOME > PHP > PHP Forum > ช่วยดูหน่อยครับ session ไม่ทำงานบนโฮสจริงครับ แต่บน localhost ไม่มีปัญหาครับ



 

ช่วยดูหน่อยครับ session ไม่ทำงานบนโฮสจริงครับ แต่บน localhost ไม่มีปัญหาครับ

 



Topic : 068714



โพสกระทู้ ( 11 )
บทความ ( 0 )



สถานะออฟไลน์




ปัญหาคือการเช็คว่าสมาชิกได้ทำการเข้าสู่ระบบแล้วหรือยัง

ตอนผมทดสอบบน local host ไม่มีปัญหาครับ เช็คได้ว่าใครผ่านการเข้าสู่ระบบแล้ว

แต่พออัพขึ้นโฮสจริงแล้ว เช็คไม่ได้เลยครับ มันเด้งกลับไปหน้า index ตลอดเลย

ลองช่วยดูโค๊ดให้หน่อยนะครับ ว่าผิดพลาดตรงไหน



อันนี้เป็นหน้า login นะครับ
Code (PHP)
<?
ob_start();
//============ Start Session และทำการเรียก Function ติดต่อฐานข้อมูล 
session_start();
if ($sess_userid<>session_id()) { 
	echo "<h3>กรุณาเข้าสู่ระบบก่อน กำลังกลับไปหน้าหลัก</h3><hr />";
	echo'<meta http-equiv="refresh" content="3; URL=index.php">';
	exit(); 
}
?>
<?
require("./connection/connect.inc.php");
require("./connection/function.php");
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874">
<title>:::ยินดีต้อนรับ :::</title>
<link href="css/styles.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.style2 {font-size: 16px}
.style3 {font-size: 10px; }
.style4 {font-size: 9px; }
.style5 {font-weight: bold}
.style8 {color: #48eb3c}
.style9 {color: #ff7800}
.heading_column {
	font-family: "MS Sans Serif", "Microsoft Sans Serif", Tahoma;
	font-weight: bold;
	color: #44A601;
	padding-left: 6px;
	font-size: 18px;
}
.body_01 {
	font-size: 10pt;
	font-family: "MS Sans Serif", "Microsoft Sans Serif", Tahoma;
}
.bullete {
	font-size: 10pt;
}
.photo-caption {
	color: #1770f7;
	font-family: "Microsoft Sans Serif", "MS Sans Serif", Tahoma;
	font-size: 10pt;
}
.top-on {font-size: 36px}
.copyright {	
	color: #1770f7;
	font-family: "Microsoft Sans Serif", "MS Sans Serif", Tahoma;
	font-size: 10pt;;
}
.heading_column1 {
	font-family: "MS Sans Serif", "Microsoft Sans Serif", Tahoma;
	font-weight: bold;
	color: #FF8500;
	padding-left: 6px;
	font-size: 20px;
	height: 30px;
	border-top-width: 2px;
	border-top-style: solid;
	border-top-color: #99CC00;
	border-right-color: #99CC00;
	border-bottom-color: #FFFF66;
	border-left-color: #99CC00;
	border-bottom-width: 1px;
	border-bottom-style: solid;
	padding-top: 2px;
	padding-right: 2px;
	padding-bottom: 2px;
}
.link {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
	background-color: #FFFFCC;
	font-weight: bold;
}
.heading_article {
	font-size: 18px;
	font-weight: bold;
	color: #FF6600;
	background-color: #CCCCCC;
	font-family: "ms Sans Serif", "microsoft sans Serif", tahoma;
	margin: 2px;
	padding: 2px;
}
.style3 {font-size: 12px}
.style1 {font-size: 12px}
a:link {
	color: #666;
	text-decoration: none;
}
a:visited {
	text-decoration: none;
	color: #666;
}
a:hover {
	text-decoration: none;
	color: #F60;
}
a:active {
	text-decoration: none;
	color: #F60;
}
</style>
</head>
<body topmargin="0">
<table width="778" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#FFFFFF">
  <tr> 
    <td bgcolor="#FFFFFF"> <table width="100%" border="0" cellpadding="0" cellspacing="0">
        <tr> 
          <td>
            <?php require_once('./menu/head.php'); ?></td>
        </tr>
        <tr> 
          <td><table width="100%" border="0" cellpadding="0" cellspacing="0" bordercolor="#f2f2f6" bgcolor="#FFFFFF">
              <tr> 
                <td width="18%" valign="top"><table width="181" border="0">
                  <tr>
                    <td width="175">
					<?php require_once('./menu/menusession.php'); ?>
					</td>
                  </tr>
                </table></td><td width="64%" valign="top"><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="body_01">
                  <!--DWLayoutTable-->
                  <tr>
                    <td width="417" bgcolor="#FFFFFF"><!--DWLayoutEmptyCell-->&nbsp;</td>
                  </tr>
                  <tr>
                    <td><!--DWLayoutEmptyCell-->&nbsp;</td>
                  </tr>
                  <tr>
                    <td><img src="images/Icon/new.gif" width="460" height="35"></td>
                  </tr>
                  <tr>
                    <td align="center"><!--DWLayoutEmptyCell-->&nbsp;</td>
                  </tr>
                  <tr>
                    <td align="center"><!--DWLayoutEmptyCell-->&nbsp;</td>
                  </tr>
                  <tr>
                    <td align="center"><img src="images/012.jpg" width="520" height="175"></td>
                  </tr>
                  <tr>
                    <td height="20" bgcolor="#FFFFFF" class="style3"><img src="images/Icon/St.gif" width="460" height="35"></td>
                  </tr>
                  <tr>
                    <td height="19" bgcolor="#FFFFFF" class="body_01">&nbsp;</td>
                  </tr>
                  <tr>
                    <td bgcolor="#FFFFFF" class="body_01"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                          <td>&nbsp;</td>
                          <td class="body_01">&nbsp;</td>
                        </tr>
                        <tr>
                          <td>&nbsp;</td>
                          <td class="body_01">&nbsp;</td>
                        </tr>
                        <tr>
                          <td>&nbsp;</td>
                          <td class="body_01">&nbsp;</td>
                        </tr>
                        <tr>
                          <td width="11%">&nbsp;</td>
                          <td width="89%" class="style3">&nbsp;</td>
                        </tr>
                    </table></td>
                  </tr>
                  <tr>
                    <td bgcolor="#FFFFFF" class="body_01">&nbsp;</td>
                  </tr>
                  <tr>
                    <td bgcolor="#FFFFFF" class="body_01"><span class="style3"><img src="images/Icon/Te.gif" width="460" height="35"></span></td>
                  </tr>
                  <tr>
                    <td bgcolor="#FFFFFF" class="body_01">&nbsp;</td>
                  </tr>
                  <tr>
                    <td bgcolor="#FFFFFF" class="body_01"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                          <td width="11%">&nbsp;</td>
                          <td width="89%">&nbsp;</td>
                        </tr>
                        <tr>
                          <td>&nbsp;</td>
                          <td>&nbsp;</td>
                        </tr>
                    </table></td>
                  </tr>
                  <tr>
                    <td bgcolor="#FFFFFF">&nbsp;</td>
                  </tr>
                </table></td>
                <td width="18%" valign="top"> <?php require_once('./menu/menuright.php'); ?> </td>
              </tr>
              <tr> 
                <td colspan="3" valign="top">
                  <?php require_once('./menu/down.php'); ?>
                </td>
              </tr>
          </table></td>
        </tr>
      </table></td>
  </tr>
</table>
</body>
</html>




ส่วนอันนี้เป็นการเช็คครับ
Code (PHP)
<?
session_start();
?>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<?
$user_login=$_POST[username];
$pass_login=$_POST[password];

if ($user_login=="" or $pass_login=="") {
	echo "<h3>ERROR : กรุณาเข้าสู่ระบบก่อน<h3>";
	echo'<meta http-equiv="refresh" content="2; URL=index.php">'; exit();
}
include "./connection/connect.inc.php";
$sql="select * from register where user_username='$user_login' and user_password='$pass_login'";
$result=mysql_db_query($database_connect,$sql);
$num=mysql_num_rows($result);
$record=mysql_fetch_array($result);

if($num<=0) {
	echo "<h3>ERROR : username หรือ password ผิด กลับไปหน้าแรก</h3>";
	echo'<meta http-equiv="refresh" content="2; URL=index.php">';
} else {
	$username=$record[user_id];
	$status=$record[status];
	$_SESSION["loginname"]=$username;
	$_SESSION["loginstatus"]=$status;
	if($status=="admin"){
	session_register("sess_adminid");
	$sess_adminid=session_id();
	echo'<meta http-equiv="refresh" content="2; URL=./admin/indexadmin.php">';
	echo'<meta http-equiv="refresh" content="2; URL=indexlogin.php">';
	}
	else{
	session_register("sess_userid");
	$sess_userid=session_id();
	echo'<meta http-equiv="refresh" content="2; URL=indexlogin.php">';
	}
	echo "<h3>กำลังเข้าสู่ระบบ กรุณารอซักครู่</h3><hr />
";


	
}
mysql_close();
?>




Tag : PHP







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2011-11-03 22:42:15 By : redarmy_yoona View : 1329 Reply : 6
 

 

No. 1



โพสกระทู้ ( 708 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

ลอง echo session_id(); มาดูครับ แล้วลอง refresh page ดู ว่า ค่ามันเปลี่ยนหรือไม่






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-11-03 23:49:13 By : kerb
 


 

No. 2



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

มี Error หรือไม่ครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-11-04 06:37:18 By : webmaster
 

 

No. 3



โพสกระทู้ ( 11 )
บทความ ( 0 )



สถานะออฟไลน์


ไม่มี error ครับ

แต่ session มันไม่ทำงานอ่ะครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-11-04 13:05:36 By : redarmy_yoona
 


 

No. 4



โพสกระทู้ ( 11 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 1 เขียนโดย : kerb เมื่อวันที่ 2011-11-03 23:49:13
รายละเอียดของการตอบ ::
ค่าไม่เปลี่ยนครับ ลองเปลี่ยน user แล้ว

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-11-04 16:50:34 By : redarmy_yoona
 


 

No. 5

Guest


แก้ได้ยังครับ ของผมก็เป็น ยังแก้ไม่ได้เลย มีใครแก้ได้บ้างครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-05-08 09:34:07 By : นายเอ
 


 

No. 6



โพสกระทู้ ( 106 )
บทความ ( 0 )



สถานะออฟไลน์


หน้า login ไม่ต้อง เช็ค ได้ปะ

Code (PHP)
if ($sess_userid<>session_id()) { 
	echo "<h3>กรุณาเข้าสู่ระบบก่อน กำลังกลับไปหน้าหลัก</h3><hr />";
	echo'<meta http-equiv="refresh" content="3; URL=index.php">';
	exit(); 
}



เออออกได้มั๊ย
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-05-08 10:18:34 By : pongit50
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ช่วยดูหน่อยครับ session ไม่ทำงานบนโฮสจริงครับ แต่บน localhost ไม่มีปัญหาครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 01
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่