Table of Contents
php effectively prevents the same user from logging in multiple times, php effectively prevents login
Home Backend Development PHP Tutorial php effectively prevents the same user from logging in multiple times, php effectively prevents login_PHP tutorial

php effectively prevents the same user from logging in multiple times, php effectively prevents login_PHP tutorial

Jul 12, 2016 am 09:04 AM
php

php effectively prevents the same user from logging in multiple times, php effectively prevents login

[Problem description]: If the same user logs in multiple times at the same time, it cannot be detected It's dangerous to come out. Because, you have no way of knowing if other users are logging into your account. How to prevent the same user from logging in multiple times?
【Solution】
(1) Each time you log in and the identity authentication is successful, a session_id will be regenerated.

1

2

session_regenerate_id();

session_register ("username") ;

Copy after login

(2) Open a sessionid field in the user database, and update this field after regenerating session_id.

1

2

3

4

5

$sessionid = session_id();

$db = new PDO('sqlite:softToken.db');

$sql = "update userinfo set sessionid ='$sessionid' where username='$username' and passwd='$passwd';";

$query = $db->prepare($sql);

$query->execute();

Copy after login

(3) Create a session to save the username

1

$_SESSION["username"] = $username;

Copy after login

(4) Use url rewriting and pass session_id

1

2

3

4

$url = "main.php?sid=".session_id();

unset($db);

echo "<font color=blue>登录成功,正在跳转!</font>" ;

header ("Location:$url");

Copy after login

(5) Add
at the beginning of the page you want to jump to
main.php

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

<&#63;php

header('Content-type:text/html; charset=utf-8');

$sessionid = $_GET['sid'];

session_id($sessionid);

session_start ();

$username = $_SESSION["username"];

$db = new PDO('sqlite:softToken.db');

$sql = "select * from userinfo where username='$username' and sessionid='$sessionid';";

$query = $db->prepare($sql);

$query->execute();

$user = $query->fetch(PDO::FETCH_OBJ);

  

if ($user->username == ""){

session_destroy();

echo "<script language='javascript' type='text/javascript'>" ;

echo "window.location.href = 'index.html';" ;

echo "</script>" ;

exit () ;

}

&#63;>

  

<html>

<body>

......

</body>

</html>

Copy after login

The above is PHP’s solution to effectively prevent multiple logins to the same account at the same time. I hope it will be helpful to everyone in solving the problem of multiple logins to the same account at the same time.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1073122.htmlTechArticlephp effectively prevents the same user from logging in multiple times, php effectively prevents login [Problem Description]: The same user logs in multiple times at the same time If the login cannot be detected, it is dangerous. Because you have no...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP Working with Database CakePHP Working with Database Sep 10, 2024 pm 05:25 PM

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

In this chapter, we are going to learn the following topics related to routing ?

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

See all articles