私のサイトでは、新しいメンバーが登録されると問題が発生し、プロフィールページに表示され、データがプルアップされるはずです。ユーザーが登録すると、セッション変数が保存されません
現在、「そのユーザーは存在しません」ということを除いて、プロフィールページに表示されます。なぜなら、セッション変数を保存していないようだからです。この新しいメンバーをログアウトしてログインし直すと、新しいセッションですべて正常に動作します。
この原因は何ですか?問題の解決に役立つコードがいくつかあります。コードがもっと必要な場合は教えてください。ほんのちょうど、パスはregister.phpページに行き、その後profile.phpページにリダイレクトされるので、profile.phpコードも提供します。
関数である:register.phpため
//adds a user to the database
function add_user($user, $pass){
$user = mysql_real_escape_string(htmlentities($user));
$pass = sha1($pass);
mysql_query("INSERT INTO `users` (`user_name`, `user_password`) VALUES ('{$user}', '{$pass}')");
}
コードは次のとおり
<?php
include('core/init.inc.php');
$errors = array();
if (isset($_POST['username'], $_POST['password'], $_POST['repeat_password'])){
if (empty($_POST['username'])){
$errors[] = 'The username cannot be empty.';
}
if (empty($_POST['password']) || empty($_POST['repeat_password'])){
$errors[] = 'The password cannot be empty.';
}
if ($_POST['password'] !== $_POST['repeat_password']){
$errors[] = 'Password verification failed.';
}
if (user_exists($_POST['username'])){
$errors[] = 'The username you entered is already taken.';
}
if (empty($errors)){
add_user($_POST['username'], $_POST['password']);
$_SESSION['username'] = htmlentities($_POST['username']);
header('Location: profile.php');
die();
}
}
?>
profile.phpコードである:
<?php
include('core/init.inc.php');
if (isset($_GET['uid']) && $_GET['uid'] !='')
{
$user_info = fetch_user_info($_GET['uid']);
}
else
{
$user_info = fetch_user_info($_SESSION['uid']);
}
?>
機能fetch_user_infoである: //フェッチ指定されたユーザーのプロファイル情報 function fetch_user_ info($ uid){ $ uid =(int)$ uid;
<?php
session_start();
$exceptions = array('register', 'login', 'find', 'profile');
$page = substr(end(explode('/', $_SERVER['SCRIPT_NAME'])), 0, -4);
mysql_connect('localhost', 'root', 'root');
mysql_select_db('user_system');
$path = dirname(__FILE__);
include("{$path}/inc/user.inc.php");
if (isset($_COOKIE['username'], $_COOKIE['password']) && isset($_SESSION['username']) === false){
if ($uid = valid_credentials($_COOKIE['username'], $_COOKIE['password'])){
$_SESSION['username'] = htmlentities($_COOKIE['username']);
$_SESSION['uid'] = $uid;
setcookie('username', $_COOKIE['username'], time() + 604800);
setcookie('password', $_COOKIE['password'], time() + 604800);
}
}
if (in_array($page, $exceptions) === false){
if (isset($_SESSION['username']) === false){
header('Location: login.php');
die();
}
}
?>
あなたは 'session_start()'を呼び出していますか? –
いいえ、私はregister.phpまたはprofile.phpで呼び出されていませんでしたが、私はそれを追加しようとしましたが、残念ながら問題を修正しませんでした。 – soshannad