I. User registration and login

include './header.php';
    include './function.php';

    $username = p('username');
    $password = p('password');
    $password2 = p('password2');

    if ($password! =$password2) {
        redirect("./login.php"."Two different passwords entered.", 3);
    }

    if (!$username || !$password) {
        redirect("./login.php"."Please enter username or secret", 3);
    }

    $redis= connRedis(); /* User table Settings user:id:1:username user:id:1:password user:username 1 */$id = $redis->incr("global:user");
    $redis->set("user:id:$id:username".$username);
    $redis->set("user:id:$id:password".$password);
    $redis->set("user:username:$username".$id); // Maintain a table with the latest 50 users$redis->lpush("newuser".$id);
    $redis->ltrim("newuser", 0, 49);

    redirect("./login.php"."User name:$usernameRegistration successful", 3); include'./header.php';
    include './function.php';

    $username = p('username');
    $password = p('password');
    if (!$username || !$password) {
        redirect("./login.php"."Please enter username or secret", 3);
    }

    $redis = connRedis();
    $id = $redis->get("user:username:$username");
    $oldPassword = $redis->get("user:id:$id:password");
    closeRedis($redis);
    if ($password! =$oldPassword) {
        redirect("./login.php"."Incorrect username or secret", 3); } // setcookie setcookie("id".$id);
    setcookie("username".$username);
    setcookie("password".$password);
    redirect("./home.php"."Login successful", 3);Copy the code

Ii. Publication trends

include './header.php';
    include './function.php';

    $status = p('status');
    if (empty($status)) {
        redirect("./home.php"."Please enter the content", 3); } /* Post :id:1: id:1:content */$redis = connRedis();
    $id = $redis->incr("global:post");

    $redis->hMset("post:id:$id", array("uid"= >$_COOKIE['id']."content"= >$status."time" => date("Y-m-d H:i:s", time()), "username"= >$_COOKIE['username'])); // The last 50 messages published$redis->lpush("newpost".$id);
    $redis->ltrim("newpost", 0, 49); // Get my followers and send them my updates$fans = $redis->smembers("flowing:userid:{$_COOKIE['id']}");
    $fans[] = $_COOKIE['id'];
    foreach ($fans as $fansid) {
        $redis->lpush("receivepost:$fansid".$id);
    }Copy the code

Three, attention page

include './header.php';
    include './function.php';

    $uid = g("uid");
    $f = g("f");
    $redis = connRedis();
    $u = $redis->get("user:id:$uid:username");
    if (!$u) {
        redirect("./home.php"."Illegal data", 3);
    }
    if ($f) {// attention$redis->sAdd("flow:userid:{$_COOKIE['id']}".$uid);
        $redis->sAdd("flowing:userid:$uid".$_COOKIE['id']);
        $msg = "Focus on success";
    }else{/ / cancelled$redis->srem("flow:userid:{$_COOKIE['id']}".$uid);
        $redis->srem("flowing:userid:$uid".$_COOKIE['id']);
        $msg = "Unfollow succeeded";
    }
    redirect("./profile.php? u=$u".$msg, 3);Copy the code

Hot pages

include_once("./header.php");
    include_once("./function.php");
    if (!$_COOKIE['id']) {
        redirect("./login.php"."Please log in first.", 3);
    }
    $redis = connRedis();
    $data = $redis->sort("newuser", array("get"= >"user:id:*:username"."limit"= > array (0, 1),"sort"= >"desc")); // Get the latest published dynamic ID$newpost = $redis->lRange("newpost", 0, 1);Copy the code

I hope the above content can help you. Many PHPer will encounter some problems and bottlenecks when they are advanced, and they have no sense of direction when writing too many business codes. I have sorted out some information, including but not limited to: Distributed architecture, high scalability, high performance, high concurrency, server performance tuning, TP6, Laravel, YII2, Redis, Swoft, Kafka, Mysql optimization, shell scripting, Docker, microservices, Nginx, etc. Many knowledge points are free to share with you