我在用户级别系统遇到问题时,我想根据您是否登录而不同的方式显示不同的内容,而我尝试的任何内容都没有。我可以回复一个正常的字符串就好了,但我使用if语句来检查用户级别我什么也得不到。我有一个带有示例用户的数据库,他的user_level字段设置为1.登录过程成功,这就是我所拥有的:
顺便说一句,session_start();在包含的base.php中。
<!DOCTYPE html>
<html>
<?php
include "base.php";
?>
<head>
<title> Scenery Sample Site | Home</title>
<link href='http://fonts.googleapis.com/css?family=Lobster'
rel='stylesheet' type='text/css'>
<link href="css/bootstrap.css" rel="stylesheet">
<link href="css/main.css" rel="stylesheet">
</head>
<div class="nav">
<div class="container">
<ul class="pull-left">
<li><a href="index.html">Home</a></li>
<li><a href="#">About Us</a></li>
<li><a href="#">Pricing</a></li>
<li><a href="#">Feedback</a></li>
</ul>
<ul class="pull-right">
<?php
if($_SESSION['user_level'] = 1) {
echo $username;
}
?>
</ul>
</div>
</div>
<div class="jumbotron">
<div class="container">
<h1>Scenery for your favourite<br> destinations!</h1>
<p>Learn more about our products by clicking the link below.</p>
<p><a href="products.html">Visit our product page.</a></p>
</div>
</div>
<div class="we-offer">
<div class="container">
<div class="col-md-4">
<h3>Custom Building Models!</h3>
<p>All of our scenery models are custom made by our developers.</p>
<p><a>More Details Here!</a></p>
</div>
<div class= "col-md-4">
<h3>State of The Art Texturing!</h3>
<p>All of our scenery textures are custom, and of the highest quality. You will have to make sure you're not watching real life.</p>
<p><a>More Details Here!</a></p>
</div>
<div class="col-md-4">
<h3>Moving Jet-ways!</h3>
<p>A lot of competitors remove the functionality of moving jetways that fsx comes with. Well guess what, we don't!</p>
<p><a>More Details Here!</a></p>
</div>
</div>
<div class="container">
<div class="col-md-4">
<div class= "thumbnail">
<img src="http://goo.gl/ZRT5E6">
</div>
</div>
<div class= "col-md-4">
<div class= "thumbnail">
<img src="http://goo.gl/KsocGR">
</div>
</div>
<div class="col-md-4">
<div class= "thumbnail">
<img src="http://goo.gl/3UfG97">
</div>
</div>
</div>
</div>
</html>
答案 0 :(得分:1)
您没有检查字符串,您尝试分配它。
请记住:使用单个=您指定给变量时,您不会检查它。
你必须这样做:
if($_SESSION["user_level"] == 1) {
echo "fancy fancy";
}
答案 1 :(得分:0)
我将假设其余部分,包括设置会话值是否正确,并说: 您没有使用正确的运营商。使用双&#34; =&#34;。
if($_SESSION['user_level'] == 1) {
echo $username;
}
答案 2 :(得分:0)
您要分配而不是检查,这应该有所帮助:
<?php
if($_SESSION['user_level'] == 1) {
echo $username;
}
?>