gaku-ura/hide_php/user_page.php

139 行
4.0 KiB
PHP

<?php
//直接アクセスしちゃだめ
require $d_root.'/hide_php/conf/c.php';
require $d_root.'/hide_php/conf/submit.php';
require $d_root.'/hide_php/conf/form.php';
require $d_root.'/hide_php/conf/bbs.php';
if (!isset($_GET['User'])){
not_found();
}
if (!isset($_GET['Key'])){
not_found();
}
$user = $_GET['User'];
$key = $_GET['Key'];
if (!not_empty($user) || !not_empty($key)){
not_found();
}
$true_user = decode_a($user);
$true_key = decode_a($key);
if (($true_user === false) || ($true_key === false)){
not_found();
}
if (strlen($user.$key) > 130){
not_found();
}
$user_data_file = $d_root.'/sqlike/user/page/'.$user.'('.$key.').txt';
$user_name = $true_user.'◆'.$true_key;
//誰?
if (file_exists($user_data_file)){
$user_data = file_get_contents($user_data_file);
} else {
$user_data = '<p>まだ利用者ページが作成されてません。</p>';
}
//利用者ファイルはある?
//投稿
if (isset($_POST['submit'])){
if (isset($_POST['session_num'])){
$session_num = h($_POST['session_num']);
$url = (isset($_SERVER['HTTP_REFERER'])?$_SERVER['HTTP_REFERER']:'unset');
if (check_session('user_page', $session_num, $url, false)){
switch ($_POST['submit']){
case 'edit':
(isset($_POST['name'])?$name = h($_POST['name']):form_die());
(isset($_POST['t_key'])?$t_key = h($_POST['t_key']):form_die());
if (($name === $true_user) && (t_key($name, $t_key) === $true_key)){
//セッション代用
$session_num = one_time_pass(50, 100);
set_session('user_page', $session_num);
//文字色リスト
$color_option = '';
foreach ($color_list as $c){
$color_option = $color_option.'<i class="'.$c.'">'.$c.'</i> ';
}
$form = '<p>このフォームでは内容にHTMLを含めることができます。</p>
<form action="" method="POST" id="form">
<h2>内容を編集</h2>
<input type="hidden" name="session_num" value="'.$session_num.'">
<p><label>名前<input type="text" name="name" value="'.$name.'"></label><label>#トリップ<input type="text" name="t_key" value="'.$t_key.'"></label></p>
<p><label>内容:<br><textarea name="content" rows="10" cols="35" id="text">'.h($user_data).'</textarea></label></p>
<p style="float:right;"><button type="submit" name="submit" value="post" class="enter">編集完了</button></p>
<p><br></p>
<p>色の一覧</p><p style="background:#ffc;">'.$color_option.'</P>
</form>';
$user_data = '';
} else {
$form = '<p>編集できません。</p>';
}
break;
case 'post':
(isset($_POST['name'])?$name = h($_POST['name']):form_die());
(isset($_POST['t_key'])?$t_key = h($_POST['t_key']):form_die());
(isset($_POST['content'])?$content=$_POST['content']:form_die());
if (($name === $true_user) && (t_key($name, $t_key) === $true_key)){
file_put_contents($user_data_file, $content, LOCK_EX);
header('Location:/user_page.php?User='.$user.'&Key='.$key);
} else {
$form = '<p>編集できません。</p>';
}
break;
default:
not_found();
break;
}
//switch終わり
} else {
$form = '暗号の認証に失敗しました。';
}
} else {
$form = '認証に失敗しました。';
}
//通常表示
} else {
$session_num = one_time_pass(50, 100);
set_session('user_page', $session_num);
}
###########html開始
html_head($user_name.'さんのページ-', '', $d_root.'/sqlike/css/form/bbs.css', true);
echo '<h1>'.$user_name.'さんのページ</h1>';
if (isset($form)){
echo $form;
} else {
echo $user_data;
}
echo '<p><br></p><p><br></p><p><br></p><hr>';
echo '<details>
<summary><p>&gt;&gt;edit(click)</p></summary>
<p>名前とトリップで編集</p><p><form action="" method="POST"><input type="hidden" name="session_num" value="'.$session_num.'">
<label>名前<input type="text" name="name" style="background:#ccc;width:100px;" value="'.(isset($_COOKIE['name'])?h($_COOKIE['name']):'').'"></label>
<label>トリップ<input type="text" name="t_key" style="background:#ccc;width:100px;" value="'.(isset($_SESSION['key'])?h($_SESSION['key']):'').'"></label>
<button type="submit" name="submit" value="edit" style="float:none;">編集</button></form></p>
</details>';
html_foot('', '');