[英]Getting value of a variable from other file php
At the beginning of both files, you should start a session:在两个文件的开头,您应该启动一个 session:
<?php
session_start();
?>
Then you should put the username in a session, like shown below:然后你应该把用户名放在 session 中,如下所示:
<?php
if (!empty($_POST["username"]) {
$_SESSION["username"] = $_POST["username"];
} else {
echo "<p>You didn't fill in a username</p>";
}
?>
Then in the get.php file remove the "require_once login.php" line, and add the variable $username like so:然后在 get.php 文件中删除“require_once login.php”行,并添加变量 $username,如下所示:
<?php
$username = $_SESSION["username"];
$sql = "SELECT firstname, contactnum FROM tb_register WHERE username= '".$username."'";
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.