本文作者:DurkBlue

PHP Record the number of login users

DurkBlue 2019-12-02 1745 抢沙发
PHP Record the number of login users摘要: Function to record how many times the user logs inConnect to the database first:you can cr...

Function to record how many times the user logs in

Connect to the database first:
you can create a new php file :
The following code:

php file name is conn.php
<?php
    header("Content-type:text/html;charset=utf-8");
    $conn = mysql_connect('localhost','root','') or die('Server connection failed');
    mysql_select_db('database name') or die('database nonexistence');;
    mysql_query('set names utf-8');
?>

you can create a new php file :
The following code:

php file name is login.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " 
<html xmlns=" 
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>login</title>
</head>
<body>
    <form action="logindo.php" method="post">
       users: <input name="name" type="text"/><br/>
       cipher:<input name="password" type="password"/></br>
       <input type="submit" name="sub" value="submit"/>
    </form>
</body>
</html>

you can create a new php file :
The following code:

file named :logindo.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " 
<html xmlns=" 
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>login handling</title>
</head>
<body>
<?php
    if(isset($_POST['sub'])){
    include('conn.php');       
    $name = $_POST['name'];       
    $password = $_POST['password'];       
    $sql = "select * from tb_name where name = '$name' and password = '$password'";       
    $r = mysql_query($sql);       
    if($row = mysql_fetch_array($r)){
           session_start();           
           $_SESSION['name']=$row['name'];           
           $ac = 0;           
           if(file_exists("acc.txt")){               
           $ac = file_get_contents("acc.txt");
           }           
           $ac++;
           file_put_contents("acc.txt",$ac);           
           echo '<script>alert('login success');location.href="index.php";
           </script>';
           }else{           
           echo '<script>alert("user name or password error");location.href="login.php";</script>';
           }
        }else{        
        echo '<script>alert("user name or password error");location.href="login.php";</script>';
     }else{     
     echo '<script>alert("user name or password error");location.href="login.php";</script>';
     }?>  
     </body>
     </html>

you can create a new php file :
The following code:

index.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " 
<html xmlns=" 
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>User registration login procedure</title>
</head>
<body><?php
  session_start();  
  if(isset($_SESSION['name'])){    
  echo 'welcome'.$_SESSION['name'];    
  echo "<br>";    
  $ac = file_get_contents("acc.txt");    
  echo "you are".$ac."visitor";
    }else{    
    echo "<script>alert('please login');location='loginl.php';</script>";
    }
    ?>
    <a href="exit.php">Logged out</a>
    </body>
    </html>

you can create a new php file :
The following code:

file name is exit.php
<?php
  header("Content-type:text/html;charset=utf-8");
  session_start();
  unset($_SEEION['name']);
  echo '<script>alert("exit the success");location="login.php";</script>';
?>

The datadase is as follows:

create database (database);use (database);create table (table_name);create table 'table_name'  ( 'id' int(4) not null auto_increment primary key,'name' varchar(50) character set utf8 collate utf8_unicode_ci not null,'password' varchar(50) character set utf8 collate utf8_unicode_ci not null,'createtime' datetime not null ) engine = myisan character set utf8 collate utf8_unicode_ci;

welcome to view


此篇文章由DurkBlue博客申请发布,转载吧请注明来处
文章投稿或转载声明

来源:DurkBlue版权归原作者所有,转载请保留出处。本站文章发布于 2019-12-02
温馨提示:文章内容系作者个人观点,不代表DurkBlue博客对其观点赞同或支持。

赞(0)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏

阅读
分享

发表评论取消回复

快捷回复:
AddoilApplauseBadlaughBombCoffeeFabulousFacepalmFecesFrownHeyhaInsidiousKeepFightingNoProbPigHeadShockedSinistersmileSlapSocialSweatTolaughWatermelonWittyWowYeahYellowdog

评论列表 (暂无评论,1745人围观)参与讨论

还没有评论,来说两句吧...