未定义指数:用户名在C:\\ XAMPP \\ htdocs中\\ HMS \\ login.php中上线927 [英] Undefined index: username in C:\xampp\htdocs\hms\login.php on line 927
本文介绍了未定义指数:用户名在C:\\ XAMPP \\ htdocs中\\ HMS \\ login.php中上线927的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有问题登录并销毁会话创建。的反馈是:
I am having problem login out and destroying session created. the feed back are:
Notice: Undefined index: username in C:\xampp\htdocs\hms\login.php on line 927
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\hms\login.php:241) in C:\xampp\htdocs\hms\login.php on line 927
Notice: Undefined variable: _SESSION in C:\xampp\htdocs\hms\login.php on line 928
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\hms\login.php:241) in C:\xampp\htdocs\hms\login.php on line 929
在这些行引用的code是
241线至275:
The referenced code in those line are Line 241 to 275:
<?php
require("include/dbinfo.php");
$link=mysql_connect($server,$user,$pass)or die(errorReport(mysql_error()));
mysql_select_db($db,$link)or die(errorReport(mysql_error()));
if(!isset($_GET['pid']))
{
echo "<div><link rel=\"stylesheet\" href=\"css/style01.css\">";
$username=$_COOKIE['username'];
$sessionid=$_COOKIE['PHPSESSID'];
$row=mysql_query("select * from session where username='$username' and id='$sessionid'");
if(!empty($row)&&(mysql_num_rows($row)))
{
$result=mysql_query("select * from employee where Employee_ID='$username'");
if($row=mysql_fetch_array($result))
{
$name=$row['Name'];
$eid=$row['Employee_ID'];
$dept=$row['Dept_No'];
$gender=$row['Gender'];
$contact=$row['Contact'];
$dob=$row['DOB'];
$add=$row['Address'];
echo "<h3>Personal Details</h3>";
echo "<table border=0 cellpadding=1 cellspacing=0 style=\"margin:5px 0px 0px -3px;\">";
echo "<tr><td width=5%>Name: </td><td width=50%>$name</td></tr>";
echo "<tr><td>Employee ID: </td><td>$eid</td></tr>";
echo "<tr><td>Date of Birth: </td><td>$dob</td></tr>";
echo "<tr><td>Department: </td><td>$dept</td></tr>";
echo "<tr><td>Contact: </td><td>$contact</td></tr>";
echo "<tr><td>Gender: </td><td>$gender</td></tr>";
echo "<tr><td>Address: </td><td>$add</td></tr>";
echo "</table>";
}
}
echo "</div>";
920线至931:
Line 920 to 931:
else if(isset($_GET['pid'])&&(strcmp($_GET['pid'],"logout")==0))
{
$username=$_COOKIE['username'];
$sessionid=$_COOKIE['PHPSESSID'];
if(mysql_query("select * from session where username='$username' and id='$sessionid'"))
{
$result=mysql_query("delete from session where username='$username'and id='$sessionid'");
setcookie("username",$_POST['username'],time()-3600);
unset($_SESSION['PHPSESSID']);
header('Location: index.php');
}
echo "</div>";
请,这里有什么问题?
推荐答案
您没有设置未设置($ _ SESSION ['PHPSESSID']);
,但你不要有在session_start()
来启动它。请把它放在℃后,右上角; PHP
标记。
因为你没有张贴用户名
价值,但其在cookie中,你把它定义为 $用户名
,更改此
You unset unset($_SESSION['PHPSESSID']);
but you dont have session_start()
to start it. Please put it at the top right after the <?php
tags.
Because you are not posting the username
value but its in the cookie, and you defined it as $username
, Change this
setcookie("username",$_POST['username'],time()-3600);
要
setcookie("username",$username,time()-3600);
这篇关于未定义指数:用户名在C:\\ XAMPP \\ htdocs中\\ HMS \\ login.php中上线927的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文