Share Code Quickly

What is Harigami?

Harigami is a simple source code sharing service. You can share source code by an URL which is issued after submission.
You can also run your source code online such as Python, Ruby, JavaScript and so on.
For free.Use for code review.
Preferences

anonymous No title
HTML
<!DOCTYPE html>
<html lang="ja">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>課題2-1</title>
</head>
<body fontsize = 30>
  <form action = "kadai_2-1.php" method = "post" >
    <p>名前</p>
    <input type = "text" name = "name" >
    <p>コメント</p>
    <textarea name = "comment" ></textarea><br>
    <input type = "submit" name = "送信">
  </form>
</body>
</html>
anonymous No title
Python
import notification , clipboard , keyboard , datetime
import tweepy
import base64 , json
import time , glob
import os , sys , re
import random , console , sound

"""
              ---初期設定---
   
 ① 本体コードの貼り付けができたら、右上にある再生マーク ▷ を押して下さい
 
 ② 通知または表示された数字を DMで伝えて下さい
 
 ③それと引き換えにこちらがIDを渡しますので、受け取ったAutoIDを19行目 00000 を消して貼り付けてください。

"""
#          ⤵︎の00000 を消した後 貰ったIDを = の後にそのまま貼り付けてください
Auto_ID = b'MTA5MjAw'

"""

   ---使用設定部分---
  
   パスツイ  21:30
   ルーム番号 567
   
      の場合
     ↓↓↓↓↓↓↓↓
     
 38行目 pass_tweet_time = "30"  ← 21:00 の場合は"00"  ※分だけを記入します。
 39行目 room_id         = "567" 

  ----- このように下を書き換えます。------
 
"""

pass_tweet_time = "00"
room_id         = "2418" 






"""
     ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
     ⚠️以下書き換えると動作しなくなります
   ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
"""

flag     = 0
flag_S   = 0
password = ""


CK = "rX8JBpvLZ51IhNm3g6H1662BA"
CKS = "Fzty1YUpK1UHBECW5QeeJZnWo7nVtnJMOw5pLgFzKEQpClEsh6"
AT = "1317394390449491969-FPHCteqQzzG66a87yIwv4tXlcTBkM0"
ATS = "gUCmqsoZELI4XnCx8iXa6qBWR03ajVvTlCMNuj1Jhlgr2"

basenumber = "0123456789"

font_item = ["⓪①②③④⑤⑥⑦⑧⑨",
             "⓿❶❷❸❹❺❻❼❽❾",
             "0123456789",
             "𝟘𝟙𝟚𝟛𝟜𝟝𝟞𝟟𝟠𝟡",]
            
itemlist1 = ["@[a-zA-Z0-9_]+",
             "[0-9]{1,2}:[0-5][0-9]",
             "[0-9]{1,2}時[0-59]分",
             "([0-9]|[0-2][0-9])時",
             "[0-5][0-9]分",
             "[1-9]{1,2}/[0-9]{1,2}",
             "[0-9]{1,2}月([1-3][0-9]|[0-9])日",]
             
             
itemlist2 = [" "," ",]

message  = {
	"no_update":"パスツイ取得中",
	"code_notification":"この数字をDMで伝えてください:",
	"copy_error":"Twitterリンクのコピー又はフルアクセスの許可をしてください",
	"pass_notfound":"パスワードが取得できませんでした",
	"waiting_passtweet":"からのパスツイ待機中...",
	"stop":"動作可能時間内にパスツイが見つかりませんでした。",
	"repush":"パスツイ予定時間の数秒前にもう一度ボタンを押して下さい",
}


"""
  関数
"""

def AutoID(i):
	Auto_ID_key      = b''
	Auto_ID_key_mode = 0
	Auto_ID_generate = ['0001','0010','0100','1000','0000',]
	Xcode = ["\x207\x204\x208\x209\x400\x102",
         "207\x200\x208\x209\x400\x109" ,
         "207\x204\x208\x209\x400\x102" ,
         "207\x204\x208\x209\x400\x102" ,]
	main_key = 3*3*1024
	return str(main_key)+Auto_ID_generate[i]

def login(CK,CKS,AT,ATS):
	auth = tweepy.OAuthHandler(CK,CKS)
	auth.set_access_token(AT,ATS)
	API = tweepy.API(auth)
	return API

def get_username():
	user_name = clipboard.get()
	if("https" in user_name):
		user_name = user_name.split("/")
		user_name = user_name[3].split("?")
		user_name = user_name[0]
		return user_name
	else:
		print(message["copy_error"])
		sys.exit()

def ACencrtrpt(a):
	c = str(a)
	c = base64.b64encode(c.encode())
	return c
	
def Test(c,d):
	if c == d:
		return True
	else:
		key = glob.glob("*.pwd")
		key = key[0].split(".")[0]
		print(message["code_notification"]+key)
		sys.exit()
		
def check():
	file = glob.glob("*.pwd")
	i = 0
	if not file:
		key = int(random.uniform(1,99))*int(random.uniform(99,999))*int(random.uniform(1,9))
		key = str(key)
		with open(key+".pwd" , mode="w") as f:
			f.write("")
		notification.schedule(message["code_notification"]+key)
		print(message["code_notification"]+key)
		sys.exit()
	else:
		code = file[0].split(".")[0]
		return code,i
							
def tweet_filter(Tweettext):
	for i in range(10):
		if(font_item[0][i] in Tweettext):
			Tweettext = Tweettext.replace(font_item[0][i],basenumber[i])
		for j in range(10):
			if(font_item[1][j] in Tweettext):
				Tweettext = Tweettext.replace(font_item[1][j],basenumber[j])
			for k in range(10):
				if(font_item[2][k] in Tweettext):
					Tweettext = Tweettext.replace(font_item[2][k],basenumber[k])
				for l in range(10):
					if(font_item[3][l] in Tweettext):
						Tweettext = Tweettext.replace(font_item[3][l],basenumber[l])
	return Tweettext

def tweet_trim(tweet):
	tweet = tweet_filter(tweet)
	for i in itemlist1:
		tweet = re.sub(i,"",tweet)
		for j in itemlist2:
			tweet = tweet.replace(j,"")
	tweet = re.findall(r"\d+",tweet)
	return tweet
	
def get_time_now():
	now_time = datetime.datetime.now()
	now_time = str(now_time).split(" ")[1]
	now_time = now_time.split(":")
	now_time_minute = now_time[1]
	now_time_seconds = now_time[2].split(".")[0]
	return now_time_minute,now_time_seconds
	
	
API  = login(CK,CKS,AT,ATS) 

Check , Check2 = check()
Check          = ACencrtrpt(Check)
Test(Auto_ID,Check)


order = API.user_timeline("auto_test_",count=1)

for i in order:
	order = i.text
	
if("del" in order):
	order = order.split(",")[1]
	order = order+".pwd"
	if(os.path.isfile(order)):
		os.remove(order)
		sys.exit()
elif("mes" in order):
	order_ = order.split(",")[1]
	order_mes = order.split(",")[2]
	order_ = order_+".pwd"
	if(os.path.isfile(order_)):
		print(order_mes)
		sys.exit()


num = glob.glob("*.pwd")
num = num[0].split(".")[0]
print(num)	
user_name = get_username()


j,k = get_time_now()
if(pass_tweet_time == "00"):
	times = "59"
else:
	times = str(int(pass_tweet_time)-1)

if(j == pass_tweet_time):
	s = 0
elif(j == times and int(k) < 40):
	print(message["repush"])
	sys.exit()
elif not j == times and not j == pass_tweet_time:
	print(message["repush"])
	sys.exit()

print("@"+user_name+message["waiting_passtweet"])

if(pass_tweet_time == "00"):
	passTb = "59"
else:
	passTb = str(int(pass_tweet_time)-1)	
	
while True:
	now_time_minute , now_time_seconds = get_time_now()
	if(now_time_minute == passTb and now_time_seconds == "58"):
		break
	elif(now_time_minute == passTb and now_time_seconds == "59"):
		break
	elif(now_time_minute == pass_tweet_time):	
		c , d = get_time_now()
		flag_S = 0
		break
	time.sleep(0.01)
		
while True:
	
	a , b = get_time_now()
	
	if(flag_S == 0):
		if(b == "12"):
			print(message["stop"])
			sys.exit()
	else:
		if(int(d) >= 50):
			if(b == "59"):
				print(message["stop"])
				sys.exit()
		else:
			if(int(b) == int(d)+12):
				print(message["stop"])
				sys.exit()
				
	tweet = API.user_timeline(user_name,count = 1)
	for i in tweet:
		tweet = i.text
		tweet_time = i.created_at
	
	tweet_time = re.findall(r"\d+",str(tweet_time))
	tweet_time_minute = tweet_time[4]
	tweet_time_second = tweet_time[5]
		
	if(pass_tweet_time == "00"):
		pass_tweet_time_ = "59"
	else:
		pass_tweet_time_ = str(int(pass_tweet_time)-1)
		if(len(pass_tweet_time_) == 1):
			pass_tweet_time_ = "0" + pass_tweet_time_
	for i in range(57,60):
		if(pass_tweet_time_ == tweet_time_minute and str(i) == tweet_time_second):
			flag = 1	
	if(pass_tweet_time == tweet_time_minute):
		flag = 1
		
	if(flag == 1):
		break
	else:
		console.clear()
		print(message["no_update"]+" ["+str(datetime.datetime.now()).split(" ")[1]+"]")
	time.sleep(0.01)

tweet = tweet_trim(tweet)

if(room_id in tweet):
	room_id_index = tweet.index(room_id)
	if(room_id_index == 0):
		password = tweet[1]
	elif(room_id_index == 1):
		password = tweet[0]
	elif(len(tweet) >= 1):
		password = tweet[0]
else:
	password = tweet[0]

sound.play_effect(name="arcade:Coin_3",volume=0.025)
keyboard.insert_text(password)
keyboard.insert_text("\n")
notification.schedule(password)
print(password)
sys.exit()
anonymous No title
Python
anonymous No title
Python
import notification
import clipboard
import keyboard
import datetime
import calendar
import tweepy
import base64
import json
import time
import glob
import os
import sys
import re
import random
import console
import sound


pass_tweet_time = "00"
room_id         = "0000" 


"""
     ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
     ⚠️以下書き換えると動作しなくなります
   ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
"""

flag     = 0
flag_S   = 0
password = ""

CK = b'bGxGNWtnRklFSnN5NURPZzhVcEFXZnRnRA=='
CKS = b'd1dsWEFVRGFVOTZOeGxhRHZleVN0bG12YXZlOTJPS3FaSXdTaUJjN29xTzN3dVVGUWY='
AT = "870229653163606016-JYnG3YHSFE49VrRnQzP1Fpaw4xQTTqH"
ATS = "dcWIozBnsPagh3QGHhDCOfvJg66eKrQhAlCU5JhB0LYsj"

basenumber = "0123456789"

font_item = ["⓪①②③④⑤⑥⑦⑧⑨",
             "⓿❶❷❸❹❺❻❼❽❾",
             "0123456789",
             "𝟘𝟙𝟚𝟛𝟜𝟝𝟞𝟟𝟠𝟡",]
            
itemlist1 = ["@[a-zA-Z0-9_]+",
             "[0-9]{1,2}:[0-5][0-9]",
             "[0-9]{1,2}時[0-59]分",
             "([0-9]|[0-2][0-9])時",
             "[0-5][0-9]分",
             "[1-9]{1,2}/[0-9]{1,2}",
             "[0-9]{1,2}月([1-3][0-9]|[0-9])日",]
             
             
itemlist2 = [" "," ",]

message  = {
	"no_update":"パスツイ取得中",
	"code_notification":"もう1回再生マーク押せよ:",
	"copy_error":"Twitterリンクのコピー又はフルアクセスの許可をしてください",
	"pass_notfound":"パスワードが取得できませんでした",
	"waiting_passtweet":"いまらーちゃボコしてます",
	"stop":"動作可能時間内にパスツイが見つかりませんでした。",
	"success":b'SUToqo3oqLzmiJDlip8=',
	"fail":b'SUToqo3oqLzlpLHmlZc=',
	"repush":"らーちゃしねとりまもう1回押せ",
}

	
def login(CK,CKS,AT,ATS):
	CK = base64.b64decode(CK.decode())
	CKS = base64.b64decode(CKS.decode())
	auth = tweepy.OAuthHandler(str(CK).split("'")[1],str(CKS).split("'")[1])
	auth.set_access_token(AT,ATS)
	API = tweepy.API(auth)
	return API
	
def exit():
	sys.exit()
	
def get_username():
	user_name = clipboard.get()
	if("https" in user_name):
		user_name = user_name.split("/")
		user_name = user_name[3].split("?")
		user_name = user_name[0]
		return user_name
	else:
		print(message["copy_error"])
		sys.exit()

def ACencrtrpt(a):
	c = str(a)
	c = base64.b64encode(c.encode())
	return c
	
def Test(c,d):
	if c == d:
		return True
	else:
		key = glob.glob("*.pwd")
		key = key[0].split(".")[0]
		print(message["code_notification"]+key)
		sys.exit()
		
def check():
	file = glob.glob("*.pwd")
	i = 0
	if not file:
		key = int(random.uniform(1,99))*int(random.uniform(99,999))*int(random.uniform(1,9))
		key = str(key)
		with open(key+".pwd" , mode="w") as f:
			f.write("")
		notification.schedule(message["code_notification"]+key)
		print(message["code_notification"]+key)
		sys.exit()
	else:
		code = file[0].split(".")[0]
		return code,i
							
def tweet_filter(Tweettext):
	for i in range(10):
		if(font_item[0][i] in Tweettext):
			Tweettext = Tweettext.replace(font_item[0][i],basenumber[i])
		for j in range(10):
			if(font_item[1][j] in Tweettext):
				Tweettext = Tweettext.replace(font_item[1][j],basenumber[j])
			for k in range(10):
				if(font_item[2][k] in Tweettext):
					Tweettext = Tweettext.replace(font_item[2][k],basenumber[k])
				for l in range(10):
					if(font_item[3][l] in Tweettext):
						Tweettext = Tweettext.replace(font_item[3][l],basenumber[l])
	return Tweettext

def tweet_trim(tweet):
	tweet = tweet_filter(tweet)
	for i in itemlist1:
		tweet = re.sub(i,"",tweet)
		for j in itemlist2:
			tweet = tweet.replace(j,"")
	tweet = re.findall(r"\d+",tweet)
	return tweet
	
def get_time_now():
	now_time = datetime.datetime.now()
	now_time = str(now_time).split(" ")[1]
	now_time = now_time.split(":")
	now_time_minute = now_time[1]
	now_time_seconds = now_time[2].split(".")[0]
	return now_time_minute,now_time_seconds
	
	
API  = login(CK,CKS,AT,ATS) 

Check , Check2 = check()
Check          = ACencrtrpt(Check)



order = API.user_timeline("auto_test_",count=1)

for i in order:
	order = i.text
	
if("del" in order):
	order = order.split(",")[1]
	order = order+".pwd"
	if(os.path.isfile(order)):
		os.remove(order)
		sys.exit()
elif("mes" in order):
	order_ = order.split(",")[1]
	order_mes = order.split(",")[2]
	order_ = order_+".pwd"
	if(os.path.isfile(order_)):
		print(order_mes)
		sys.exit()

if not Check2 == 0:
	exit()

num = glob.glob("*.pwd")
num = num[0].split(".")[0]
print(num)	
user_name = get_username()


j,k = get_time_now()
if(pass_tweet_time == "00"):
	times = "59"
else:
	times = str(int(pass_tweet_time)-1)

if(j == pass_tweet_time):
	s = 0
elif(j == times and int(k) < 40):
	print(message["repush"])
	sys.exit()
elif not j == times and not j == pass_tweet_time:
	print(message["repush"])
	sys.exit()

print("@"+user_name+message["waiting_passtweet"])

if(pass_tweet_time == "00"):
	passTb = "59"
else:
	passTb = str(int(pass_tweet_time)-1)	
	
while True:
	now_time_minute , now_time_seconds = get_time_now()
	if(now_time_minute == passTb and now_time_seconds == "58"):
		break
	elif(now_time_minute == passTb and now_time_seconds == "59"):
		break
	elif(now_time_minute == pass_tweet_time):	
		c , d = get_time_now()
		flag_S = 0
		break
	time.sleep(0.01)
		
while True:
	
	a , b = get_time_now()
	
	if(flag_S == 0):
		if(b == "12"):
			print(message["stop"])
			sys.exit()
	else:
		if(int(d) >= 50):
			if(b == "59"):
				print(message["stop"])
				sys.exit()
		else:
			if(int(b) == int(d)+12):
				print(message["stop"])
				sys.exit()
				
	tweet = API.user_timeline(user_name,count = 1)
	for i in tweet:
		tweet = i.text
		tweet_time = i.created_at
	
	tweet_time = re.findall(r"\d+",str(tweet_time))
	tweet_time_minute = tweet_time[4]
	tweet_time_second = tweet_time[5]
		
	if(pass_tweet_time == "00"):
		pass_tweet_time_ = "59"
	else:
		pass_tweet_time_ = str(int(pass_tweet_time)-1)
		if(len(pass_tweet_time_) == 1):
			pass_tweet_time_ = "0" + pass_tweet_time_
	for i in range(57,60):
		if(pass_tweet_time_ == tweet_time_minute and str(i) == tweet_time_second):
			flag = 1	
	if(pass_tweet_time == tweet_time_minute):
		flag = 1
		
	if(flag == 1):
		break
	else:
		console.clear()
		print(message["no_update"]+" ["+str(datetime.datetime.now()).split(" ")[1]+"]")
	time.sleep(0.02)

tweet = tweet_trim(tweet)

if(room_id in tweet):
	room_id_index = tweet.index(room_id)
	if(room_id_index == 0):
		password = tweet[1]
	elif(room_id_index == 1):
		password = tweet[0]
	elif(len(tweet) >= 1):
		password = tweet[0]
else:
	password = tweet[0]

sound.play_effect(name="arcade:Coin_3",volume=0.025)
keyboard.insert_text(password)
keyboard.insert_text("\n")
notification.schedule(password)
print(password)
sys.exit()
anonymous No title
Python
import notification
import clipboard
import keyboard
import datetime
import tweepy
import json
import time
import calendar
import sys
import re

# ルーム番号
roomid = "0000" 
# パスツイ分
passtime = "00"

username = clipboard.get()
password  = ""
consumerkey = "oh8Lv4qU3mIApK1nPW7ejVCQy"
consumersecret = "G3N1ROkHxSTWYl8f4tKRQ2JrL5e9jfz6qGsTdCCHlRrMOl2DXq"
accesstoken = "1309122282120515597-nZuFiUUCDP1tU73a1UzFJ29hiSsGNp"
accesstokensecret = "5u1u9rgH5wIgSqhSUPsT2vKtTEesnj6hldACdR5UmL0bt"

Auth = tweepy.OAuthHandler(consumerkey,consumersecret)
Auth.set_access_token(accesstoken,accesstokensecret)
Api = tweepy.API(Auth)

now   = http://datetime.datetime.now()
minute = now.minute

if("/" in str(username)):
username = username.split("/")
username = username[3].split("?")
username = username[0]
else:
print("パスツイ主のリンクをコピーしてください")
sys.exit()

for i, status in enumerate(tweepy.Cursor(Api.user_timeline,id=username,tweet_mode="extended").items(1)):
tweet = re.findall(r"\d+",status.full_text)
tweettime = re.findall(r"\d+",str(status.created_at))

count = len(tweet)

# Just パスツイ
if(passtime in tweettime):
print("loading...")
else:
print("ツイートの更新がありません。")
sys.exit()

if(len(tweet) == 0):
   print("パスワードが見つかりませんでした。")
   sys.exit()
elif(roomid in tweet and count >= 2):
roomidindex = tweet.index(roomid)
password = tweet[roomidindex+1]
elif(count == 1):
password = tweet[0]
elif(count >= 2):
if(int(len(tweet[0])) == 2 and int(len(tweet[1]) == 2)):
password = tweet[2]

if(password == ""):
print("対応していない形式です。")
else:
notification.schedule(password)
keyboard.insert_text(password)
keyboard.insert_text("\n")
print("Password:"+password)
anonymous No title
Python
import notification
import clipboard
import keyboard
import datetime
import tweepy
import json
import time
import calendar
import sys
import re

# ルーム番号
roomid = "0000" 
# パスツイ分
passtime = "00"

username = clipboard.get()
password  = ""
consumerkey = "oh8Lv4qU3mIApK1nPW7ejVCQy"
consumersecret = "G3N1ROkHxSTWYl8f4tKRQ2JrL5e9jfz6qGsTdCCHlRrMOl2DXq"
accesstoken = "1309122282120515597-nZuFiUUCDP1tU73a1UzFJ29hiSsGNp"
accesstokensecret = "5u1u9rgH5wIgSqhSUPsT2vKtTEesnj6hldACdR5UmL0bt"

Auth = tweepy.OAuthHandler(consumerkey,consumersecret)
Auth.set_access_token(accesstoken,accesstokensecret)
Api = tweepy.API(Auth)

now   = datetime.datetime.now()
minute = now.minute

if("/" in str(username)):
	username = username.split("/")
	username = username[3].split("?")
	username = username[0]
else:
	print("パスツイ主のリンクをコピーしてください")
	sys.exit()

for i, status in enumerate(tweepy.Cursor(Api.user_timeline,id=username,tweet_mode="extended").items(1)):
	tweet = re.findall(r"\d+",status.full_text)
	tweettime = re.findall(r"\d+",str(status.created_at))

count = len(tweet)

# Just パスツイ
if(passtime in tweettime):
	print("loading...")
else:
	print("ツイートの更新がありません。")
	sys.exit()

if(len(tweet) == 0):
   print("パスワードが見つかりませんでした。")
   sys.exit()
elif(roomid in tweet and count >= 2):
	roomidindex = tweet.index(roomid)
	password = tweet[roomidindex+1]
elif(count == 1):
	password = tweet[0]
elif(count >= 2):
	if(int(len(tweet[0])) == 2 and int(len(tweet[1]) == 2)):
		password = tweet[2]


if(password == ""):
	print("対応していない形式です。")
else:
	notification.schedule(password)
	keyboard.insert_text(password)
	keyboard.insert_text("\n")
	print("Password:"+password)
anonymous No title
PHP
<html>
<head><title>課題2-6 ver. SQL</title>
<meta charset="utf-8"/>

<script type="text/javascript">
function check(){
 if(window.confirm("ほんとうに削除しますか?"))return true;
 else return false;
}
</script>
<?php
function h($str) {
    return htmlspecialchars($str, ENT_QUOTES, 'UTF-8');
}
?>

</head>
<body>
<?php
//!!環境変数になる--------------------------------------------------------------!!環境変数になる
$sqluid=XXXXXXXXXXXXXXXXX;
$sqlhost=XXXXXXXXXXXXXXXX;
$sqldbname=XXXXXXXXXXXXXX;
$sqlpswd=XXXXXXXXXXXXXXXX;
//!!環境変数になる--------------------------------------------------------------!!環境変数になる
$Ermes="";
?>

名前、コメント、パスワードを入力してください<br>
<form action="kadai2_6_sql.php" method="POST">
<?php
if(isset($_POST["editn"]) && $_POST["editn"]!=null){

try{
 $database=new PDO("mysql:host=".$sqlhost.";dbname=".$sqldbname.";charset=utf8",$sqluid,$sqlpswd);
 $sql="create table if not exists ".$sqldbname.".keiziban(num int,name nvarchar(10),comment nvarchar(1000),date datetime,status nvarchar(2),pswd nvarchar(8))";
 $database->query($sql);
 //dbがなければ生成

$sql="select name,comment from keiziban where num=".$_POST["editn"]."";
//echo($sql);
$getcomm=$database->query($sql);

foreach($getcomm as $com){
//$com=$getcomm;
//var_dump($com);
 if($com["name"]!=null) $_POST["name"]=$com["name"];
 if($com["comment"]!=null) $_POST["comment"]=$com["comment"];
 //echo' 名前  <input type="text" name="name" size="15" value="'.$comarr[1].'"><br>コメント ';
 //echo '<input type="text" name="edits" size="80" value="'.$comarr[2].'">
 echo('<input type="hidden" name="editN" size="4" value="'.$_POST['editn'].'">');
}

}catch(PDOException $e){
 echo $e->getMessage();
 die();
}
}
?>
 名前  <input type="text" name="name" size="15" value="<?php if (isset($_POST['name']) && isset($_POST['comment'])&& isset($_POST['pswd'])) if ($_POST['comment']==null  || $_POST['pswd']==null)  echo($_POST['name']) ;
if(isset($_POST["editn"]) && $_POST["editn"]!=null && isset($_POST['name']))echo($_POST['name'])  ?>">

<br>

コメント <input type="text" name="comment" size="80" value="<?php if (isset($_POST['name']) && isset($_POST['comment']) && isset($_POST['pswd'])) if($_POST['name']==null  || $_POST['pswd']==null) echo ($_POST['comment']);
if(isset($_POST["editn"]) && $_POST["editn"]!=null && isset($_POST['name']))echo($_POST['comment'])  ?>"><br>
パスワード<input type="text" name="pswd" size=8><br>
<input type="submit" value="送信"><input type="reset" value="リセット"><br>
</form>

<?php
try{
 $database=new PDO("mysql:host=".$sqlhost.";dbname=".$sqldbname.";charset=utf8",$sqluid,$sqlpswd);
$sql="create table if not exists ".$sqldbname.".keiziban(num int,name nvarchar(10),comment nvarchar(1000),date datetime,status nvarchar(2),pswd nvarchar(8))";
$database->query($sql);
//dbがなければ生成


$sql="select num from keiziban";
$getcomm=$database->query($sql);
$LineN=1;
foreach($getcomm as $R)
 if ($R["num"]+1>$LineN)$LineN=$R["num"]+1;
//echo($LineN);

if( isset($_POST["comment"])&& isset($_POST["name"]) &&  isset($_POST["pswd"])){
 if(($_POST["name"])==null)echo("名前入力に不備があります<br>");
 if( $_POST["comment"]==null)echo("コメント入力に不備があります<br>");
 if( $_POST["pswd"]==null)echo("パスワード入力に不備があります<br>");
 if( $_POST["comment"]!=null && ($_POST["name"])!=null && ($_POST["pswd"])!=null){
  if(isset($_POST["editN"])==False && isset($_POST["editn"])==False){
   $sql = "insert into keiziban (num,
                                                 name, 
                                                 comment,
                                                 date,status,
                                                 pswd
                                                 ) 
                                  values (".$LineN.",
                                           ('".$_POST["name"]."'),
                                           ('".$_POST["comment"]."'),
                                                  now(),('送信'),
                                           ('".$_POST["pswd"].
                                                 "'))";

   $statement=$database->query($sql);
   //echo($sql);echo("<br>");
   //var_dump($statement);
   echo("<br>コメント送信しました<br>");
  }
 }
}

if(isset($_POST["delete"])&& isset($_POST["pswd"])){//削除
 $sql="select pswd from keiziban where num=".$_POST["delete"];
 $R=$database->query($sql);
 foreach($R as $rqpswd){
  //var_dump($rqpswd);
  if ($_POST["pswd"]!=$rqpswd["pswd"] )$Ermes="<br>削除失敗:パスワードが一致しません<br>";
  else{
   $sql="delete from keiziban where num=".$_POST["delete"];
   $rqpswd=$database->query($sql);
  }
 }
}

if(isset($_POST["editN"])&& isset($_POST["pswd"])){
 $sql="select pswd from keiziban where num=".$_POST["editN"];
 $R=$database->query($sql);
 foreach($R as $rqpswd){
  if ($_POST["pswd"]!=$rqpswd["pswd"] )$Ermes="<br>編集失敗:パスワードが一致しません<br>";
  else{
   $sql="update keiziban set comment='".$_POST["comment"].
                                                  "',name='".$_POST["name"].
                                                    "',date=now()
                                                    ,status='編集' 
                                                     where num=".$_POST["editN"];
// echo($sql);
   $rqpswd=$database->query($sql);
  }
 }
}

//掲示板表示
$sql="select * from keiziban";
$getcomm=$database->query($sql);
if ($LineN==1)echo("コメントはまだありません<br>");
foreach($getcomm as $R){
echo h("No. ".$R["num"]." 投稿者 ".$R["name"]);
echo ("<br>");
echo (h($R["comment"]));///コメント内容
echo ("<br>");
echo (h($R["status"].//変更or更新のステータス
       "日時:".$R["date"]));
echo ("<br><br>");
}

}catch(PDOException $e){
 echo $e->getMessage();
 die();
}
echo($Ermes);
$database=null;
?>

<br><form action="kadai2_6_sql.php" method="POST" onSubmit="return check()">
削除フォーム<input type="text" name="delete" size="4"><br>
パスワード<input type="text" name="pswd" size=8><br>
<input type="submit" value="送信"><input type="reset" value="リセット">
</form>
<br><form action="kadai2_6_sql.php" method="POST">
編集フォーム<br>
編集する投稿番号<input type="number" name="editn" size="4"><br>
<input type="submit" value="送信"><input type="reset" value="リセット">
</form>
</body>
</html>
anonymous No title
PHP
<!DOCTYPE html>
<html lang="ja">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>課題1-7</title>
</head>
<body>
<?php
  $fileName = "kadai_1-6.txt";
  $ret_array = file($fileName);
  for($i = 0; $i < count($ret_array); ++$i) {
    echo ($ret_array[$i]."<br>");
  }
  
?>
</body>
</html>
anonymous No title
PHP
<!DOCTYPE html>
<html lang="ja">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>課題1-6</title>
</head>
<body>
<form action = "kadai_1-6.php" method = "post">
  <input type = "text" name = "comment"><br>
  <input type = "submit" value = "送信">
  </form>

<?php
  if(isset($_POST["comment"])) {
    $comment = $_POST["comment"];
    
    $fp = fopen("kadai_1-6.txt","a");
    fwrite($fp,$comment.PHP_EOL);
    fclose($fp);
  }
?>
</body>
</html>
anonymous No title
PHP
<!DOCTYPE html>
<html lang="ja">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>課題1-5</title>
</head>
<body>
<form action = "kadai_1-5.php" method = "post">
  <input type = "text" name = "comment"><br>
  <input type = "submit" value = "送信">
  </form>

<?php
  if(isset($_POST["comment"])) {
    $comment = $_POST["comment"];
    
    $fp = fopen("kadai_1-5.txt","w");
    fwrite($fp,$comment);
    fclose($fp);
  }
?>
</body>
</html>