gpt4 book ai didi

php - 查看个人资料页面 PHP

转载 作者:行者123 更新时间:2023-11-28 12:52:02 25 4
gpt4 key购买 nike

所以我有一个管理面板,我正在为测试目的而创建,只是为了体验,我正在努力做到这一点,所以当你登录时(使用 PHP session )你可以点击按钮配置文件,它会带你到你的配置文件并显示您的姓名、电子邮件、用户组。所有这些我都在我的数据库中,但我似乎无法显示它们..

这是我的代码

<?php
include_once 'includes/db_connect.php';
include_once 'includes/functions.php';

sec_session_start();

if (isset($_GET['username'])) {
$username = mysql_real_escape_string($_GET['username']);
if (ctype_alnum($username)) {
//check user exists
$check = mysql_query("SELECT username, email, usergroup FROM members WHERE username='$username'");
if (mysql_num_rows($check)===1) {
$get = mysql_fetch_assoc($check);
$username = $get['username'];
$email = $get['email'];
$usergroup = $get['usergroup'];
} else {
echo "<h2>User does not exist!</h2>";
exit();
}
}
}
?>

<html>
<head>
<title>test</title>
<body>
<php? echo $username; ?>
</body>
</html>

那你有什么想法吗?

谢谢,

此外 - 我已经将 $username 定义为一个变量,但是当我显示它并加载页面时,它只是说 undefined variable :用户名在

最佳答案

很难确定实际错误发生的位置。那么让我们来看看吧。

让我们从您的包含开始:

include_once 'includes/db_connect.php';
include_once 'includes/functions.php';

这是两个未知来源。很难说有没有问题。

如果您检查 URI 传递的用户名:

if (isset($_GET['username'])) {

这可能会导致错误(虽然它不太可能在您的情况下调用错误),因为如果您传递一个没有值的 GET 变量键(例如 index.php?foo 导致 isset($_GET['foo']) == true,而 !empty($_GET['foo']) == false。所以使用 !empty() 而不是 isset()

检查用户名是否为字母数字:

if (ctype_alnum($username)) {

ctype_alnum() "checks if all of the characters in the provided string [...] are alphanumeric" ,错误可能是由于传递了包含非字母数字字符的用户名引起的。

您没有字母数字检查的 else {} 定义。考虑这样做,例如通过添加

if(ctype_alumn(...)) {
// ...
} else {
echo "<h2>Alphanumeric username required!</h2>";
exit();
}

您的 MySQL 提取似乎没问题,否则您的

echo "<h2>User does not exist!</h2>";   
exit();

会获取它。

最后,还可以考虑为您的 isset($_GET['username']) 检查添加 else 情况,例如像这样

if (isset($_GET['username'])) {
// ...
} else {
echo "<h2>No username provided!</h2>";
exit();
}

关于 var_dump() 用法的旁注

@Andy 评论了使用 var_dump() 转储有关 $_GET['username'] 的信息的建议。这是一个例子:

if (isset($_GET['username'])) {
var_dump($_GET['username']);
exit();
}

会打印出类似的东西

string(7) "Foo Bar"

关于php - 查看个人资料页面 PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23554724/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com