我正在使用$session[login]
,但$_SESSION
似乎无法在html/php
网页的主页上运行。它没有出现任何东西。为什么?任何人都可以帮助我
并告诉我为什么?会话名称错了吗?或者需要在里面输入php?
<html>
<title>Home</title>
<head>
<link href="SSCdesign.css" rel="stylesheet" type="text/css">
<script src="script.js"> </script>
</head>
<body>
<header id="SSClogo"><img src="SSC_logo_v2.png"></header>
<div id='userbar'>
<?php
$_SESSION['login'] = true;
while($row = mysql_fetch_assoc($result))
{
$_SESSION['student_id'] = $row['studnet_id'];
$_SESSION['student_name'] = $row['student_name'];
}
?>
</div>
<div id='wrapper' align="center">
<nav id='cssmenu'>
<ul>
<li class='active'><a href='SSC.html'><span>Home</span></a></li>
<li><a href='advisors.html'><span>Advisors</span></a></li>
<li class='has-sub'><a href='pals.html'><span>PALS</span></a>
<ul>
<li><a href='registersession.html'><span>Register Session</span></a></li>
<li><a href='timetable.html'><span>Timetable</span></a></li>
<li><a href='feedback.html'><span>Feedback</span></a></li>
<li class='last'><a href='buzz.html'><span>Buzz</span></a></li>
</ul>
</li>
<li class='has-sub'><a href='econsultation.html'><span>e-Consultation</span></a>
<ul>
<li><a href='appointment.html'><span>e-Appointment</span></a></li>
<li><a href='upcoming.html'><span>Upcoming List Appointment</span></a></li>
<li class='last'><a href='history.html'><span>History</span></a></li>
</ul>
</li>
<li class='has-sub'><a href='workshop.html'><span>Workshop</span></a>
<ul>
<li><a href='calendar.html'><span>Calendar</span></a></li>
<li class='last'><a href='eportfolio.html'><span>e-Portfolio</span></a></li>
</ul>
</li>
<li><a href='facilities.html'><span>Facilities</span></a></li>
<li class='last'><a href='contactus.html'><span>Contact Us</span></a></li>
<li class='la'><a href='login.html'><span>Login</span></a></li>
</ul>
<div id="announcement">
<h2> <center> Announcement will be posted here </center> </h2>
<p> <center> This site is currently under development, do check it out soon! </center> </p>
</div>
<div id="slideshow">
<h2> <center> Slideshow will be here </center> </h2>
</div>
</nav>
<div class="push"></div>
</div>
</body>
</html>
答案 0 :(得分:3)
在使用之前,您必须先启动会话:
session_start();
所以你的代码应该是这样的:
<?php
session_start();
$_SESSION['login'] = true;
(如果你说你使用$session[login]
,那么你必须使用它是错误的:$session['login']
否则login
是一个常数,它不是)
有关详细信息,请参阅:http://php.net/manual/en/function.session-start.php