我想实现的功能是,防止用户重复登录,太高深的方法我不懂,我只会用自己能理解的方法,高手见谅!
首先登录页
if(!$username){ $aa= '账号不存在'; }else if($password != $bb){ $aa= '密码错误'; }else if(!empty($_SESSION["username"])){ $aa= '该账号已登录'; }else{ session_start(); $_SESSION["md5"] = md5($time); $_SESSION["username"] = $account; DB::query("UPDATE ".DB::table('abc')." set a='$time' , b=' {$_SESSION["username"]}' , md5='{$_SESSION['md5']}' where name='$account'"); $aa= '成功登陆'; }
这样写有问题 似乎是没有session_start() 就使用$_SESSION["username"] 产生的问题?
如果删掉 }else if(!empty($_SESSION["username"])); 会好一些 但是任有其他问题
下面是登录跳转后的页面
session_start(); $md5 = $_SESSION["md5"]; $username = $_SESSION["username"]; $aa= DB::get_one("SELECT * FROM ".DB::table('abc')." WHERE b='$username' and md5='$md5'"); if(!$aa){ session_destroy(); echo "<script>alert('你掉线了');</script>"; echo "<script language='javascript' type='text/javascript'>" ; echo "window.location.href = 'index.php';" ; echo "</script>" ; exit () ; }}
现在的问题是 不管怎么登录 都会提示"掉线了",即时清空缓存也是一样!
如果删掉登录页的 }else if(!empty($_SESSION["username"])); 部分 会正常
但是,同浏览器多开的问题还是存在,不同的浏览器似乎有效!
本人自学小白,高手勿喷
求解!
回复讨论(解决方案)
最好贴上后报错的信息,然后如果判断$_SESSION时,如果是原生的话,是要先session_start(),当然判断的时候,最好是isset($_SESSION['xx'])是否存在的,你这问题很乱,查询也要先调试看看查询结果是什么,如果有错,那么看看查询语句最终是什么?,防止重复登录的话,用SESSION的话,只要判断SESSION是否存在,SESSION是否符合,就行了
你这个写得很乱啊
登录页 获取输入的用户名和密码,查询数据是否正确,正确就写入session,然后跳转到登录后的页面
登陆后的页面只要判断是否有该用户的session 数据就行了,若没有,就跳到登录页提示登录

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Laravel's service container and service providers are fundamental to its architecture. This article explores service containers, details service provider creation, registration, and demonstrates practical usage with examples. We'll begin with an ove

PHP logging is essential for monitoring and debugging web applications, as well as capturing critical events, errors, and runtime behavior. It provides valuable insights into system performance, helps identify issues, and supports faster troubleshoot

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Atom editor mac version download
The most popular open source editor
