<?php require_once('Connections/yiwuyiwu.php'); ?><?phpif (!function_exists("GetSQLValueString")) {function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue;}}mysql_select_db($database_yiwuyiwu, $yiwuyiwu);$query_Recordset1 = "SELECT * FROM `user`";$Recordset1 = mysql_query($query_Recordset1, $yiwuyiwu) or die(mysql_error());$row_Recordset1 = mysql_fetch_assoc($Recordset1);$totalRows_Recordset1 = mysql_num_rows($Recordset1);?><?php// *** Validate request to login to this site.if (!isset($_SESSION)) { session_start();}// ***session变量开始了$loginFormAction = $_SERVER['PHP_SELF'];if (isset($_GET['accesscheck'])) { $_SESSION['PrevUrl'] = $_GET['accesscheck'];}if (isset($_POST['Username'])) { $loginUsername=$_POST['Username']; $password=(md5($_POST['Password'])); $MM_fldUserAuthorization = "enable"; $MM_redirectLoginSuccess = "index.php"; $MM_redirectLoginFailed = "zhuce.php"; $MM_redirecttoReferrer = false; //*** 输入账号和密码,判断转向页面。 mysql_select_db($database_yiwuyiwu, $yiwuyiwu); $LoginRS__query=sprintf("SELECT u_id u_name, pass, enable FROM `user` WHERE u_name=%s AND pass=%s", //*** 启用符号是这个“·” GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); $LoginRS = mysql_query($LoginRS__query, $yiwuyiwu) or die(mysql_error()); $row_LoginRS = mysql_fetch_assoc($LoginRS); $loginFoundUser = mysql_num_rows($LoginRS); if ($loginFoundUser) { $loginStrGroup = mysql_result($LoginRS,0,'enable'); //*** 声明三个会话变量并分配值 $_SESSION['MM_Username'] = $loginUsername; $_SESSION['MM_UserGroup'] = $loginStrGroup; $_SESSION['u_id']= $row_LoginRS('u_id'); if (isset($_SESSION['PrevUrl']) && false) { $MM_redirectLoginSuccess = $_SESSION['PrevUrl']; } header("Location: " . $MM_redirectLoginSuccess ); } else { header("Location: ". $MM_redirectLoginFailed ); }}?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title></title></head><body> <h3 id="登录系统">登录系统</h3> <hr /><form ACTION="<?php echo $loginFormAction; ?>" id="form1" name="form1" method="POST"> <table width="250" border="1" align="center" cellpadding="0" cellspacing="0"> <tr> <td colspan="2" nowrap="nowrap" bgcolor="#3366CC"><div align="center"><font color="#FFFFFF">用户登陆</font></div></td> </tr> <tr> <td width="100" nowrap="nowrap"><div align="right"><font color="#000000">用户名:</font></div></td> <td width="235"> <div align="left"> <input name="Username" type="text" id="Username" /> </div></td> </tr> <tr> <td width="100" nowrap="nowrap"><div align="right"><font color="#000000">密码:</font></div></td> <td width="235"> <div align="left"> <input name="Password" type="password" id="Password" value="" /> </div></td> </tr> <tr> <td colspan="2"><div align="right"> <a href="/test/zhuce.php">注册</a> <input type="submit" name="Submit" value="登陆" /> </div></td> </tr> </table></form></body></html><?phpmysql_free_result($Recordset1);?>
回复讨论(解决方案)
你怎么知道没有生效的?
你怎么知道没有生效的?
因为登录以后我计划用session变量做了if语句,结果if语句没生效
你用了哪个session,你可以echo一下看是否有值。
你把相关代码贴出来

In PHP, you can use session_status() or session_id() to check whether the session has started. 1) Use the session_status() function. If PHP_SESSION_ACTIVE is returned, the session has been started. 2) Use the session_id() function, if a non-empty string is returned, the session has been started. Both methods can effectively check the session state, and choosing which method to use depends on the PHP version and personal preferences.

Sessionsarevitalinwebapplications,especiallyfore-commerceplatforms.Theymaintainuserdataacrossrequests,crucialforshoppingcarts,authentication,andpersonalization.InFlask,sessionscanbeimplementedusingsimplecodetomanageuserloginsanddatapersistence.

Managing concurrent session access in PHP can be done by the following methods: 1. Use the database to store session data, 2. Use Redis or Memcached, 3. Implement a session locking strategy. These methods help ensure data consistency and improve concurrency performance.

PHPsessionshaveseverallimitations:1)Storageconstraintscanleadtoperformanceissues;2)Securityvulnerabilitieslikesessionfixationattacksexist;3)Scalabilityischallengingduetoserver-specificstorage;4)Sessionexpirationmanagementcanbeproblematic;5)Datapersis

Load balancing affects session management, but can be resolved with session replication, session stickiness, and centralized session storage. 1. Session Replication Copy session data between servers. 2. Session stickiness directs user requests to the same server. 3. Centralized session storage uses independent servers such as Redis to store session data to ensure data sharing.

Sessionlockingisatechniqueusedtoensureauser'ssessionremainsexclusivetooneuseratatime.Itiscrucialforpreventingdatacorruptionandsecuritybreachesinmulti-userapplications.Sessionlockingisimplementedusingserver-sidelockingmechanisms,suchasReentrantLockinJ

Alternatives to PHP sessions include Cookies, Token-based Authentication, Database-based Sessions, and Redis/Memcached. 1.Cookies manage sessions by storing data on the client, which is simple but low in security. 2.Token-based Authentication uses tokens to verify users, which is highly secure but requires additional logic. 3.Database-basedSessions stores data in the database, which has good scalability but may affect performance. 4. Redis/Memcached uses distributed cache to improve performance and scalability, but requires additional matching

Sessionhijacking refers to an attacker impersonating a user by obtaining the user's sessionID. Prevention methods include: 1) encrypting communication using HTTPS; 2) verifying the source of the sessionID; 3) using a secure sessionID generation algorithm; 4) regularly updating the sessionID.


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Dreamweaver CS6
Visual web development tools

Dreamweaver Mac version
Visual web development tools

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

WebStorm Mac version
Useful JavaScript development tools
