私はPHPを使用して独自のカスタムCMSを作成しています。ユーザーが既に訪れた場合、どのようにページを殺すことができるか知りたいのですが。PHPでページを殺す方法
基本的に私はmessage.php
というファイルを持っています。ユーザーが最初の時間に自分のアカウントにサインインすると、ウェルカムメッセージがポップアップします。このシステムを行うために、データベースに「welcome_message」というフィールドを追加し、それを0に設定しました。メッセージは「welcome_message」が0に等しい場合にのみ表示されます。しかし、ユーザーがメッセージを見た後、実行し、 "welcome_message"を1に更新します!だから、もうメッセージは表示されません。
問題は、まだウェルカムメッセージが存在することです。たとえば、ユーザーはこのURLに手動でアクセスし、そのメッセージを再度見ることができます:
http://localhost/site_name/admin/message.php?msg=0
これを無効にする方法はありますか?このメッセージを見た後にこのメッセージを削除してクエリを追加してもはや存在しないようにして、ユーザーがそれを見ることができないようにするにはどうすればよいですか?
注:私のテーブルに新しいフィールドを設定してそこにメッセージを追加することで、この機能を実行できます。しかし、それは私が使いたい方法ではありません。あなたがよりよい解決策を知っている場合、私は本当にそれを感謝し、私に知らせてください...ここで
が私のmessage.php
のコードです:
if(isset($_GET['msg'])){
$update = new Up();
$update->Update($_SESSION["admin_username"]);
echo "
<!-- Content Wrapper. Contains page content -->
<div class='content-wrapper'>
<!-- Content Header (Page header) -->
<section class='content-header'>
<h1>
Here you can see your new message
<small><a href='http://www.zite.daygostar.ir/tutorials/messages.php' target='_blank'>tutorial</a></small>
</h1>
<ol class='breadcrumb'>
<li class='active'>message.php</li>
</ol>
</section>
<!-- Main content -->
<section class='content'>
";include_once 'php/includes/sections/welcome_message.php'; echo"
</section>
<!-- /.content -->
</div>
<!-- /.content-wrapper -->
";
}
そして、ここだUp.class.php
:
<?php
class Up
{
private $db;
public function __construct()
{
$this->db = new Connection();
$this->db = $this->db->dbConnect();
}
public function Update($name)
{
if(!empty($name))
{
$ins = $this->db->prepare("UPDATE admins SET welcome_message=1 WHERE username = ?");
$ins->bindParam(1,$name);
$ins->execute();
}
}
}
?>
そして、このクラスのdbからデータを取得しています:
<?php
class Admin
{
public $db,$username,$password,$id,$group,$Datetime,$msg,$firstname,$lastname,$login,$logout;
public function __construct()
{
$this->db = new Connection();
$this->db = $this->db->dbConnect();
}
public function getAdmin($name)
{
if(!empty($name))
{
$adm = $this->db->prepare("select * from admins where username=?");
$adm->bindParam(1,$name);
$adm->execute();
while($row = $adm->fetch())
{
$this->id = $row['id'];
$this->username = $row['username'];
$this->password = $row['password'];
$this->group = $row['group'];
$this->Datetime = $row['date_joined'];
$this->msg = $row['welcome_message'];
$this->firstname = $row['firstname'];
$this->lastname = $row['lastname'];
$this->login = $row['login'];
$this->logout = $row['logout'];
}
}
else
{
header("Location: maint/php/includes/errors/004.php");
exit();
}
}
public function getID()
{
return $this->id;
}
public function getUsername()
{
return $this->username;
}
public function getPassword()
{
return $this->password;
}
public function getGroup()
{
return $this->group;
}
public function gtDate()
{
return $this->Datetime;
}
public function msg()
{
return $this->msg;
}
public function firstName()
{
return $this->firstname;
}
public function lastName()
{
return $this->lastname;
}
public function login()
{
return $this->login;
}
public function logout()
{
return $this->logout;
}
}
?>
のこの
$ WELCOME_MESSAGE = GET格納された値のようにする必要がありますURLからの$ _GET値と比較して –
あなたは何を言っているのか分かりません。あなたが言っていることについての参考文献や記事を教えてください。 thx – drousiodrawr
彼が言っていることは(私は思う)あなたのスクリプトは、データベースのユーザーレコードから "show_message"(値0または1)のようなものを取得する必要があります。 1の場合、メッセージを表示し、DB内のユーザーレコード "show_message"を0に更新します。次回は0に設定され、ユーザーはメッセージを表示しません。何が起こるかをURLで示す必要はありません。 –