ทำหน้า Login แล้วตั้ง Header("location:?p=index.php") มันไม่ไปหน้า index.php อ่ะครับ
ตัวอย่างโค้ดครับ
<?
ob_start();
include("config.php");
?>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<script language="javascript" type="text/javascript">
function checkField() {
missinginfo = "";
if (document.form1.UserName.value == "") {
missinginfo += "\n - Username";
}
if (document.form1.PassWord.value == "") {
missinginfo += "\n - Password";
}
if (missinginfo != "") {
missinginfo = " ------\n" + "ท่านกรอกข้อมูลไม่ถูกต้องในช่องต่อไปนี้:\n" + missinginfo +
"\n-----" + "\nกรุณากลับไปกรอกอีกครั้ง";
alert(missinginfo);
return false;
}
else
return true;
}
</script>
<?php
if ($_POST[Login])
{
header("location:?p=index.php");
$CK_Q = mysql_query ("SELECT * FROM emp WHERE
User_id = '". $_POST[User_id] ."'
AND Password = '" . $_POST[Password] . "' " );
if (mysql_num_rows ($CK_Q))
{
$CK= mysql_fetch_array ($CK_Q);
$_SESSION[User_id] = $CK[User_id];
$_SESSION[Password] = $CK[Password];
$_SESSION[user_status] = $CK[user_status];
header("location:?p=index.php");
exit ();
} else {
echo "<script>alert('ID หรือ รหัสผ่านไม่ถูกต้อง')</script>";
}
}
ob_end_flush();
?>
<div align="center"><img src="ITD Logo.png" width="679" height="163" /><br />
</div>
<form action="" method="post" name="form1" id="form1" onsubmit="return checkField();">
<table width="200" border="0" align="center" cellpadding="3" cellspacing="0">
<tr>
<td><strong>เข้าสู่ระบบ</strong></td>
</tr>
<tr>
<td><input name="User_id" type="text" maxlength="5" placeholder="UserName" id="User_id"/></td>
</tr>
<tr>
<td><input name="Password" type="password" maxlength="10" placeholder="PassWord" id="Password"/></td>
</tr>
<tr>
<td><input name="Login" type="submit" value="Login" id="Login" /></td>
</tr>
</table>
</form>
ทำหน้า Login แล้วตั้ง Header("location:?p=index.php") มันไม่ไปอ่ะครับ
ตัวอย่างโค้ดครับ
<?
ob_start();
include("config.php");
?>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<script language="javascript" type="text/javascript">
function checkField() {
missinginfo = "";
if (document.form1.UserName.value == "") {
missinginfo += "\n - Username";
}
if (document.form1.PassWord.value == "") {
missinginfo += "\n - Password";
}
if (missinginfo != "") {
missinginfo = " ------\n" + "ท่านกรอกข้อมูลไม่ถูกต้องในช่องต่อไปนี้:\n" + missinginfo +
"\n-----" + "\nกรุณากลับไปกรอกอีกครั้ง";
alert(missinginfo);
return false;
}
else
return true;
}
</script>
<?php
if ($_POST[Login])
{
header("location:?p=index.php");
$CK_Q = mysql_query ("SELECT * FROM emp WHERE
User_id = '". $_POST[User_id] ."'
AND Password = '" . $_POST[Password] . "' " );
if (mysql_num_rows ($CK_Q))
{
$CK= mysql_fetch_array ($CK_Q);
$_SESSION[User_id] = $CK[User_id];
$_SESSION[Password] = $CK[Password];
$_SESSION[user_status] = $CK[user_status];
header("location:?p=index.php");
exit ();
} else {
echo "<script>alert('ID หรือ รหัสผ่านไม่ถูกต้อง')</script>";
}
}
ob_end_flush();
?>
<div align="center"><img src="ITD Logo.png" width="679" height="163" /><br />
</div>
<form action="" method="post" name="form1" id="form1" onsubmit="return checkField();">
<table width="200" border="0" align="center" cellpadding="3" cellspacing="0">
<tr>
<td><strong>เข้าสู่ระบบ</strong></td>
</tr>
<tr>
<td><input name="User_id" type="text" maxlength="5" placeholder="UserName" id="User_id"/></td>
</tr>
<tr>
<td><input name="Password" type="password" maxlength="10" placeholder="PassWord" id="Password"/></td>
</tr>
<tr>
<td><input name="Login" type="submit" value="Login" id="Login" /></td>
</tr>
</table>
</form>