[英]How to access variable inside a function() to another php file
I included the login_auth.php file to the form_login.php and now, I want to access two variable inside the function adminAutentication to the form_login.php I tried it but did not works.
login_auth.php
$uname_err= '';
$psswd_err = '';
function adminAuthentication() {
$psswd_err = "The password you entered was not valid!";
$uname_err = "No account found with that username!";
}
form_login.php
<?php include 'login_auth.php'; ?>
<form method="post">
<div class="form-group">
<span class="text-danger"><?php echo $uname_err ?></span> // problem here cannot access the variable
</div>
<div class="form-group">
<span class="text-danger"><?php echo $psswd_err; ?></span> // problem here cannot access the variable
</div>
<button type="submit" name="submit">Login</button>
</form>
在 adminAuthentication() function 中,您必须声明全局变量:
function adminAuthentication() {
global $psswd_err, $uname_err ;
$psswd_err = "The password you entered was not valid!";
$uname_err = "No account found with that username!";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.