请问我写的这个php函数体传递变量的时候为什么总是上一个函数体的值?
<?phpsession_start();require("inc/pdo.php");//矫正时区差异ini_set("date.timezone","Asia/Chongqing");$time=date("Y-m-d H:i:s");//获得客户端ip$user_ip = $_SERVER["REMOTE_ADDR"];$name=$_POST["name"];$password=$_POST["password"];emptyloginnull($name,$password);//判断传值是否为空function emptyloginnull($name,$password){$functionName='';$functionName="emptyloginnull";if(!empty($name)&&!empty($password)){//都不是空...loginSQL($name,$password);}else{ echo Msg($functionName); }}function loginSQL($name,$password){ $functionName='';$functionName=1;global $dbc;$md5PD=md5($b64=base64_encode($password));$selectUser=$dbc->prepare("select name,password,loginnumber,loginstatus from nasdaouser where name=? and password=?");$selectUser->execute(array($name,$md5PD));$userNum=$selectUser->rowCount();$res=$selectUser->fetch();if($userNum==1){ loginSuecess($name,$res,$md5PD); }else { Msg($functionName); }}//登录成功function loginSuecess($name,$res,$md5PD){$functionName='';$functionName=0;global $dbc,$user_ip,$time;$loginlog=$dbc->prepare("insert into loginlog (name,password,ip,logintime,status,loginstatus) values(?,?,?,?,?,?)");$loginlog->execute(array($name,$md5PD,$user_ip,$time,'0','0'));$userLogin=$dbc->prepare("update nasdaouser set endlogintime=? where name=?");$userLogin->execute(array($time,$name));Msg($functionName);}function Msg($functionName){ echo $functionName; switch($functionName){ case "emptyloginnull": echo "不要调戏我好吗?系统也会数数的,你根本没有输入帐号与密码!!!"; break; case 0: echo "登录成功!"; break; case 1: echo "登录失败,请检查帐号密码是否输入错误!"; }}?>
问题出自function loginSuecess,登录成功后调用msg()函数 传递的$functionName变量应当是0,但是MSG()函数体内捕捉到的却是1
回复讨论(解决方案)
function Msg($functionName){ print_r(debug_backtrace()); //观察一下是谁调用的、参数是什么 switch($functionName){ ..... }}
function Msg($functionName){ print_r(debug_backtrace()); //观察一下是谁调用的、参数是什么 switch($functionName){ ..... }}
Array ( [0] => Array ( [file] => C:\wamp\www\mjshu\login.php [line] => 40 [function] => Msg [args] => Array ( [0] => 1 ) ) [1] => Array ( [file] => C:\wamp\www\mjshu\login.php [line] => 19 [function] => loginSQL [args] => Array ( [0] => smj227227 [1] => Password ) ) [2] => Array ( [file] => C:\wamp\www\mjshu\login.php [line] => 11 [function] => emptyloginnull [args] => Array ( [0] => smj227227 [1] => Password ) ) ) 登录失败,请检查帐号密码是否输入错误!
function Msg($functionName){ print_r(debug_backtrace()); //观察一下是谁调用的、参数是什么 switch($functionName){ ..... }}
Array ( [0] => Array ( [file] => C:\wamp\www\mjshu\login.php [line] => 52 [function] => Msg [args] => Array ( [0] => 0 ) ) [1] => Array ( [file] => C:\wamp\www\mjshu\login.php [line] => 35 [function] => loginSuecess [args] => Array ( [0] => smj227227 [1] => Array ( [name] => smj227227 [0] => smj227227 [password] => b9f94ff142c0d6da23543e4e37e04ac9 [1] => b9f94ff142c0d6da23543e4e37e04ac9 [loginnumber] => [2] => [loginstatus] => 0 [3] => 0 ) [2] => b9f94ff142c0d6da23543e4e37e04ac9 ) ) [2] => Array ( [file] => C:\wamp\www\mjshu\login.php [line] => 19 [function] => loginSQL [args] => Array ( [0] => smj227227 [1] => 227227 ) ) [3] => Array ( [file] => C:\wamp\www\mjshu\login.php [line] => 11 [function] => emptyloginnull [args] => Array ( [0] => smj227227 [1] => 227227 ) ))
现在输入正确的帐号密码,也被emptyloginnull调用了...
var_dump(0 == "emptyloginnull");
传入 0 也是 case "emptyloginnull": 分支成立
var_dump(0 == "emptyloginnull");
传入 0 也是 case "emptyloginnull": 分支成立
谢谢你,大神,我再把我写好的贴上来,您帮我看看还有哪些不足和细节需要优化的可以吗?

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

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

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics

Alipay PHP...

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...
