我的问题正如标题所说:如何在网站上创建和“更新个人资料”页面?
目前,我在成功登录SESSION变量后存储了用户的用户ID,用户名和电子邮件。问题是当用户通过单击按钮更新其配置文件时,将调用名为process_updateprofile.php
的外部文件。 process_updateprofile.php
需要SESSION存储的用户ID才能更新数据库中Users表中的特定用户行。
但是,当我打印出SESSION userid变量时,它返回NULL,并且SQL查询不会执行,因为我准备好的语句中的WHERE userid=?
语句失败。
这是在我页面顶部启动会话的代码:
function sec_session_start() {
$session_name = 'sec_session_id'; // Set a custom session name
$secure = false; // Set to true if using https.
$httponly = true; // This stops javascript being able to access the session id.
ini_set('session.use_only_cookies', 1); // Forces sessions to only use cookies.
$cookieParams = session_get_cookie_params(); // Gets current cookies params.
session_set_cookie_params($cookieParams["lifetime"], $cookieParams["path"], $cookieParams["domain"], $secure, $httponly);
session_name($session_name); // Sets the session name to the one set above.
session_start(); // Start the php session
session_regenerate_id(true); // regenerated the session, delete the old one.
}
这是用户登录时将用户标识存储在SESSION变量中的代码:
$user_id = preg_replace("/[^0-9]+/", "", $user_id); // XSS protection as we might print this value
$_SESSION['user_id'] = $user_id;
$username = preg_replace("/[^a-zA-Z0-9_\- ]+/", "", $username); // XSS protection as we might print this value
$_SESSION['username'] = $username;
谢谢!