I从PHP$session['role']
标记传递用户角色,然后尝试使用jQuery基于if(!sessionRole=='admin')
语句隐藏和显示页面加载事件上的div。
<script
src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
<script type="text/ecmascript"> //script to hide show page on page load.
$(document).ready(function{
var sessionRole=<?php echo $session_ROLE ?>
if(!sessionRole=='admin'){
$('#admin_tool').hide();
}
});
</script>
<div class="col-md-4" >
<div class="widgets" style="margin-top: 15px;">
<div class='Recent'id='admin_tool' > // dive that i want to hide and show
<h4>Tools</h4>
<hr>
<div class='container'>
<div class='row'>
<div class='col'><button type='button' id="btn" class='btn btn-success btn-lg' style='min-width: 150px;'>Publish</button></div>
<div class='col'><button type='button' id="btn2" class='btn btn-warning btn-lg'style='min-width: 150px;' >Oppose</button></div>
</div>
<div class='row' style='margin-top: 10px;'>
<div class='col'><button type='button' class='btn btn-info btn-lg' style='min-width: 150px;'>Unpublish</button></div>
<div class='col'><button type='button' class='btn btn-danger btn-lg' style='min-width: 150px;'>Delete</button></div>
</div>
</div>
</div>
</div>
不要!
如果您想安全地向某类用户隐藏某些内容,请在服务器上执行。
在if
条件中包装用于管理的HTML行。
<script
src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
<div class="col-md-4" >
<div class="widgets" style="margin-top: 15px;">
<?php
if($session_ROLE == "admin"){
?>
<div class='Recent'id='admin_tool' > // dive that i want to hide and show
<h4>Tools</h4>
<hr>
<div class='container'>
<div class='row'>
<div class='col'><button type='button' id="btn" class='btn btn-success btn-lg' style='min-width: 150px;'>Publish</button></div>
<div class='col'><button type='button' id="btn2" class='btn btn-warning btn-lg'style='min-width: 150px;' >Oppose</button></div>
</div>
<div class='row' style='margin-top: 10px;'>
<div class='col'><button type='button' class='btn btn-info btn-lg' style='min-width: 150px;'>Unpublish</button></div>
<div class='col'><button type='button' class='btn btn-danger btn-lg' style='min-width: 150px;'>Delete</button></div>
</div>
</div>
</div>
<?php } // End if admin
?>
</div>