インスタンス化したと思うオブジェクトを呼び出すと、「未定義の変数」の通知が表示され続けますが、明らかにそうではありません。エラーに指を置くことができません。オブジェクトは$fgmembersiteです。エラーメッセージによると、オブジェクトは存在しません。理由について混乱しています。スクリプトのinclude/require部分でディレクトリをめちゃくちゃにするという単純なケースかもしれませんが、私はそれらを調べていて、何も問題はありません。私のファイル階層を見たいかどうか教えてください。
そして再び助けてくれてありがとう!
私は3つのPHPファイルを使用しています。
最初のものはlogin-home.phpです
<?PHP
require_once("./profile_settings/view.php");
if(!$fgmembersite->CheckLogin())
{
$fgmembersite->RedirectToURL("login.php");
exit;
}
?>
/*a bunch of stuff*/
<img id="profile_avatar" src="profile_settings/<?php echo fetchAvatarLocation(); ?>"></img>
/*a bunch of stuff*/
次に、画像を保存する場所のパス名を生成するために使用する関数を保持するview.phpがあります。
<?php
include("./include/membersite_config.php");
function fetchAvatarLocation()
{
$user_id = $fgmembersite->UserId();
$query = mysql_query("SELECT * FROM ddmembers WHERE id_user = '$user_id'");
if(mysql_num_rows($query)==0)
die("User not found!");
else
{
$row = mysql_fetch_assoc($query);
$location = $row['imagelocation'];
return $location;
}
}
?>
そして最後に私はmembersite_config.phpを持っています
<?PHP
include("fg_membersite.php");
$fgmembersite = new FGMembersite();
//Provide your site name here
$fgmembersite->SetWebsiteName('Mysitename.com');
//Provide the email address where you want to get notifications
$fgmembersite->SetAdminEmail('My.Email@Provider.net');
//Provide your database login details here:
//hostname, user name, password, database name and table name
//note that the script will create the table (for example, fgusers in this case)
//by itself on submitting register.php for the first time
$fgmembersite->InitDB(/*hostname*/'localhost',
/*username*/'user',
/*password*/'password',
/*database name*/'database',
/*table name*/'table');
//For better security. Get a random string from this link: http://tinyurl.com/randstr
// and put it here
$fgmembersite->SetRandomKey('**************');
?>
fg_membersiteは、一連の関数を格納するクラスfgmembersiteを含むファイルであり、必要な関数は...
function UserId()
{
return isset($_SESSION['userid_of_user'])?$_SESSION['userid_of_user']:'';
}
function UserName()
{
return isset($_SESSION['username_of_user'])?$_SESSION['username_of_user']:'';
}