PHP if($_GET['logout']){ 这是什么意思?

<?php
session_start();
function session_login_time() {
if(!isset($_SESSION['start'])&&!isset($_SESSION['result'])){
$_SESSION['start'] = time();
$_SESSION['result'] = 0;
}
}
function session_logout_time() {
if(!isset($_SESSION['end'])){
$_SESSION['end']=time();
$_SESSION['result']=$_SESSION['end']-$_SESSION['start'];
return $_SESSION['result'];
}
}
function clear_sessions() {
unset($_SESSION['start']);
unset($_SESSION['end']);
unset($_SESSION['result']);
}
if(!empty($_POST['username'])){
$name = $_POST['username'];
$pwd = $_POST['userpwd'];
if($name = 'admin' && $pwd = 'admin'){
session_login_time();
echo "<script>alert('登陆成功!');location='login_in_out.php'</script>";
}else{
echo "<script>alert('登陆失败!');location='login.php'</script>";
}
}
if($_GET['logout']){
?>

<!doctype>
<div style='width:300px;line-height:30px;margin:auto;border:1px solid #ccc;text-align:center;color:white;font-size:14px;background:#ccc;'>统计用户在线时长</div>
</div>
<div style="width:300px;line-height:30px;margin:auto;border:1px solid #ccc;text-align:center;color:blue;font-size:14px;background:white;">
<?php
$re = session_logout_time();
echo "注销登陆前您一共在线<b><font color='red'>".($re)."</font></b>秒!";
clear_sessions();
?>
</div>
<?php
}
?>
if($_GET['logout']){
?>
它后面有?>,是不是表示php文件结束。但if里面没有语句哦

判断$_GET['logout']是否存在,相当于if($_GET['logout'] == true){或者if(isset($_GET['logout'])){
$_GET['logout'] 获取到GET提交方式下的'logout参数的值
isset() 函数的作用是检测变量是否设置
最好这样判断比较全面:
if(isset($_GET['logout']) && $_GET['logout'] != ''){
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2016-10-31
if($_GET['logout'])
$_GET中php系统常量,用来获取地址栏的传值
如a.com?logout=logout
那么获取的就是logout
if是用来判断$_GET['logout']是否存在。追问

if($_GET['logout']){
?>
它后面有?>,是不是表示php文件结束。但if里面没有语句哦。

追答

这是后台代码与html结合的一种写法

1){ ?>
a大于1; 这里就是判断A>1时运行的内容

a小于或等于1 这里就是判断A不大于1时运行的内容

本回答被提问者采纳
第2个回答  2015-10-20
这么写都是不规范的,会报一个notice警告,意思是判断是否想这个页面以get方式传入了一个logout的变量

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网