当前位置:首页 > PHP问题 > 正文内容

php怎样推断用户是不是登录【php问题】,php,登录

搜教程4年前 (2019-11-27)PHP问题160

以下实例经由过程 Session 来推断用户是不是登录:

PHP session 变量用于存储关于用户会话(session)的信息,或许变动用户会话(session)的设置。Session 变量存储单一用户的信息,而且关于应用程序中的一切页面都是可用的。

引荐:php服务器

functions.php

<?php 
function loggedIn(){ 
    //经由过程 $_SESSION  来推断用户是不是登录
    if(!$_SESSION['loggd']){ 
        echo'<form action="checkLogin.php" method="post"> 
        <p> 
            Username:<br> 
            <input type="text" name="username"> 
        </p> 
        <p> 
            Password:<br> 
            <input type="password" name="username"> 
        </p> 
        <p> 
            <input type="submit" name="submit" value="Log In"> 
        </p> 
        </form>'; 
    }else{  // 登录显现迎接页面
        echo 'Welcome, '.$_SESSION['username']; 
    } } ?>

index.php

<?php 
//Start the session 
session_start(); 

//This is a simplified HTML Document 
?> 
<html>
<head>
<title>My Page</title>
</head>
<body>
     <?php 
    // 引入 functions.php 文件
    require_once("functions.php"); 
    //登录状况显现用户名,未登录显现登录表单
    logedIn(); 
    ?> 
</body>
</html>

以上就是php怎样推断用户是不是登录的细致内容,更多请关注ki4网别的相干文章!

扫描二维码推送至手机访问。

版权声明:本文由搜教程网发布,如需转载请注明出处。

本文链接:https://www.sojiaocheng.cn/13404.html

标签: php登录
分享给朋友:

“php怎样推断用户是不是登录【php问题】,php,登录” 的相关文章

php array_unique函数怎样用?【php问题】,php,array_unique函数

php array_unique函数怎样用?【php问题】,php,array_unique函数

array_unique()是PHP中的内置函数,语法为array_unique(array ,sort_flags),用于从数组中删除反复值。假如数组中有多个元素具有雷同的值,则将保存第一个涌现的元素,而且从数组中将其他雷同值的元素删除。 php array_unique()函数怎样用?...

php is_uploaded_file函数怎样用【php问题】,php is_uploaded_file

php is_uploaded_file函数怎样用【php问题】,php is_uploaded_file

php is_uploaded_file函数用于推断指定的文件是不是是经由过程 HTTP POST 上传的,其语法是is_uploaded_file(file),参数file必须,指规定要搜检的文件。 php is_uploaded_file函数怎样用? 作用:推断指定的文件是不是是经由...

php connection_status函数怎样用【php问题】,php connection_status

php connection_status函数怎样用【php问题】,php connection_status

php connection_status函数用于返回当前的衔接状况,其语法是connection_status(),返回值是返回衔接状况位字段。 php connection_status函数怎样用? 定义和用法 connection_status() 函数返回当前的衔接状况。 可...

php html_entity_decode函数怎样用【php问题】,php,html_entity_decode函数

php html_entity_decode函数怎样用【php问题】,php,html_entity_decode函数

html_entity_decode()函数用于把 HTML 实体转换为字符,语法为html_entity_decode(string,flags,character-set)。 php html_entity_decode()函数怎样用? html_entity_decode() 函数...

php is_int函数怎样用【php问题】,php is_int

php is_int函数怎样用【php问题】,php is_int

php is_int函数用于检测变量是不是是整数,其语法是bool is_int ( mixed $var ),参数var许可传入恣意参数。 php is_int函数怎样用? 定义和用法 is_int() — 检测变量是不是是整数 语法 bool is_int ( mixed $v...

php next函数怎样用【php问题】,php next

php next函数怎样用【php问题】,php next

php next函数用于将内部指针指向数组中的下一个元素,并输出,其语法是next(array),参数array必须,指划定要运用的数组。 php next函数怎样用? 定义和用法 next() 函数将内部指针指向数组中的下一个元素,并输出。 相干的要领: prev() - 将内部...