|
|
|
สอบถาม เรื่อง cookie login ทำไมใช้กับ chorme และ ie ไม่ได้ ตัวอย่าง ด้านในครับ |
|
|
|
|
|
|
|
ช่วยแนะนำหน่อยครับว่าทำไม ผมถึงใช้มันกับ google chorme และ IE ไม่ได้ เพราะเวลาผมปิด-แล้วเปิดมาค่ามันจะหาย แต่ใช้กับ
Firefox ได้ครับไม่มีปัญหา ขอบคุณครับ
page_login.php
<?php if ($_COOKIE["username"] != "" ) { ?><? //setcookie("username",$username,time()+3600*24*356);?>
<script language="javascript">
window.location = 'index.php' ;
</script> <? } ?>
<?php require_once('Connections/sales.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;
}
}
if (isset($_POST['username'])) {
$check = $_POST['check']; //รับค่าตัวแปร checkbox
$username = $_POST['username'];
$password = $_POST['password'];
mysql_select_db($database_sales, $sales);
$query_rscemployee = "SELECT * FROM employee WHERE Username = '$username' and Password = '$password'";
$rscemployee = mysql_query($query_rscemployee, $sales) or die(mysql_error());
$row_rscemployee = mysql_fetch_assoc($rscemployee);
$totalRows_rscemployee = mysql_num_rows($rscemployee);
if($totalRows_rscemployee>0) //ถ้ามากกว่า 0
{
if ($check == "true") //ถ้าเช็คบ๊อคเข้ามา
{
setcookie('username', $username,time()+3600*24*356);//เซ็ตคุกกี้ 1ปี
header("Location: success.php"); //ส่งไปยังหน้าที่ตอ้งการ
}
else
{
setcookie('username', $username);//ไม่ต้องกำหนดเวลาให้คุกกี้
//พอปิดหน้าเพจคุกกี้จะตายทันที
header("Location: index.php"); //ส่งไปยังหน้าที่ตอ้งการ
}
}
else
{
?>
<script language="javascript">
alert("Username or password incorrect");
window.location = 'page_login.php' ;
</script>
<?
}}
?>
หน้าอื่นๆผมใส่แบบเช็คค่า cookie แบบนี้ในกรณีไม่มีค่า cookie
<?php if ($_COOKIE["username"] != "" ) { ?><? //setcookie("username",$username,time()+3600*24*356);?>
<script language="javascript">
window.location = 'index.php' ;
</script> <? } ?>
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2015-02-09 09:18:30 |
By :
natt500 |
View :
1133 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|