2015年9月26日土曜日

覚えておく

覚えておく


   function mobile_menu(){
         var get = document.getElementsByClassName("menu_item");
for(var i in get){
if(get[i].childNodes){
                                      console.log(i);
                                      get[i].style.display="none";
                                }
                    }
    }


この場合、if(get[i].childNodes) は必須な判断になります。そうしないと、

get の length、item、namedItem は除外されません、エラーになります。

2015年9月11日金曜日

Lynx (ウェブブラウザ)

Lynx (ウェブブラウザ)

日本語版
     Lynx286rel4TH.zip (Select a Mirror for File Page)
     Version 2.8.6rel.4TH, 2.9 Mbyte, 2006.5.3


This page contains links to the February 14, 2014 Lynx v2.8.8 release.

https://lynx-win32-pata.osdn.jp/index-ja.html
Lynx for Win32 (by patakuti): Project Home Page






2015年8月29日土曜日

HTTP_USER_AGENT

HTTP_USER_AGENT


Mozilla/5.0 (Linux; Android 5.0.2; ASUS_Z00ED Build/LRX22G) AppleWebKit/
537.36 (KHTML, like Gecko) Chrome/39.0.2171.93 Mobile Safari/537.36


Mozilla/5.0 (Linux; Android 5.0; ALE-L02 Build/HuaweiALE-L02) AppleWebKi
t/537.36 (KHTML, like Gecko) Chrome/39.0.2171.93 Mobile Safari/537.36


Mozilla/5.0 (Linux; Android 4.4.4; HM NOTE 1LTE Build/KTU84P) AppleWebKi
t/537.36 (KHTML, like Gecko) Chrome/44.0.2403.133 Mobile Safari/537.36

JSON.parse() && JSON.stringify()

JSON.parse()

概要
JSON.parse() メソッドは文字列を JSON として解析し、また任意で解析によって作り出された値を変換します。

構文
JSON.parse(text[, reviver])



JSON.stringify()
概要
JSON.stringify() メソッドは JavaScript の値を JSON 文字列に変換します。置き換え関数を指定して値を置き換えたり、置き換え配列を指定して指定されたプロパティのみを含むようにしたりできます。

構文
JSON.stringify(value[, replacer[, space]])

2015年8月24日月曜日

SQLITE データーベースのデーター追加(途中の記録)

SQLITE データーベースのデーター追加(途中の記録)

<?php
error_reporting(E_ALL);
date_default_timezone_set('Asia/Tokyo');
//print_r(SQLite3::version());

//
//
//
//


$x = new xtext();
echo json_encode($x->title('title',json_decode($_REQUEST['p'])));

class xtext {
public $db_name = 'xtext.db';
//
public function xtext(){
}

//
public function title($title,$paras){

$para['ad_ip'] = $_SERVER['REMOTE_ADDR'];
$para['ad_agent'] = $this->agent($_SERVER['HTTP_USER_AGENT'],"agent");
$para['ad_time'] = $_SERVER["REQUEST_TIME"];
$para['access_time'] = $_SERVER["REQUEST_TIME"];
$para['set_active'] = '1';
$para['ad_user'] = htmlentities($paras->ad_user);
$para['ad_ps'] =  htmlentities($paras->ad_ps);
$para['title'] =  htmlentities($paras->title);

$table_name = 'title';
$url_id = $this->uniq_id('title');
$this->update($table_name,$url_id,$para);

//test pint print_r($para);
return $url_id;
}


//
public function update($table,$url_id,$para ){
$db = new sqlite3($this->db_name);
foreach ($para as $key=>$val){
$insert = sprintf("update %s set %s = \"%s\" where url_id == \"%s\"" , $table,$key,$val,$url_id);
$db->exec($insert);
}
$db->close();
return 'ture';
}

// Uniquid
public function uniq_id($table_name){
$str = array(range('z','a'),range('Z','A'),range('9','0'));
$length = 11;
$str_r =array();
for ($i=0; $i<$length ;$i++){
$temp = $str[array_rand($str)];
$str_r[count($str_r)] = $temp[array_rand($temp)];
}

$db = new sqlite3($this->db_name);
do{
do{
shuffle($str_r);
$temp_id_str = implode($str_r);
$id_check = $db->querySingle(sprintf("select * from %s where url_id='%s'",$table_name,$temp_id_str),true);
if($id_check){
print_r ( $id_check);
}
}while($id_check);

$insert = sprintf("insert into %s(url_id)VALUES('%s')",$table_name,$temp_id_str);
$check = $db->exec($insert);
if($check){
$db->close();
return $temp_id_str;
}
}while(!$check);

}

// Agent
public function agent($agent,$table_name){
$db = new sqlite3($this->db_name);
$up = sprintf("update %s set count = count +1 where agent == '%s'",$table_name,$agent);
$db->exec($up);
$sch = sprintf("select ROWID from %s where agent == '%s'",$table_name,$agent);
$rowid = $db->querySingle($sch);
if(is_null($rowid)){
$new = sprintf("insert into %s (agent,count)values('%s',1)",$table_name,$agent);
$db->exec($new);
$db->close();
return 1;
}else{
$db->close();
return $rowid;
}
$db->close();
}

}


?>

SQLITE データーベース 作成 PHP

SQLITE  データーベース 作成 PHP


<?php
error_reporting(E_ALL);
date_default_timezone_set('Asia/Tokyo');
print_r(SQLite3::version());

if(!file_exists('xtext.db')){
$db = new sqlite3('xtext.db');
$create_title =
"create table title (
url_id text UNIQUE,
title text,
ad_user text default 'admin',
ad_ps text default 'admin_password',
ad_ip text default '0.0.0.0',
ad_agent text default 'Mozilla/5.0',
ad_time text default current_timestamp,
access_time text default current_timestamp,
set_active text default '1',
request_cont integer default 0,
sue_cont integer default 0)";
// set_active 1=非公開、2=公開、3=限定公開、4=削除
// sue_cont >10 非公開
//
$db->exec($create_title);

$create_items =
"create table items (
title_ROWID integer,
item text
)";
$db->exec($create_items);

$create_endusers =
"create table end_user (
url_id UNIQUE,
title_ROWID integer,
item_ROWID integer,
end_name text,
end_ip text default '0.0.0.0',
end_time text default current_timestamp
)";
$db->exec($create_endusers);


$create_agents =
"create table agent (
agent text,
count integer default 0
)";
$db->exec($create_agents);
$db->close();


}else{
echo 'exists';
}
exit;
?>

2015年8月16日日曜日

ランダム文字列 その2

ランダム文字列 その2


function mf_rand()で作成した文字列は重複することがよくあります。
今回の変更は、function mf_rand()は文字列のArrayを作成することに
し、データーベースの比較して、重複する場合、文字列の順番を変える
ことにしました。


<?php
set_time_limit(0);

$db = new sqlite3('xtext.db');
$db->busyTimeout(10000);

for ($i=0; $i<3000; $i++){
//$temp_id = uniqid(mf_rand());
//$temp_id = uniqid();
$temp_id = mf_rand();
do{
shuffle($temp_id);
$temp_id_str = implode($temp_id);
$id_check = $db->querySingle(sprintf("select * from title where url_id='%s'",$temp_id_str),true);
if($id_check){
//print_r ( $id_check);
}
}while($id_check);
$insert = sprintf("insert into title(url_id)VALUES('%s')",$temp_id_str);
$db->exec($insert);
}
$db->close();

function mf_rand(){
$str = array(range('z','a'),range('Z','A'),range('9','0'));
$length = 11;
$str_r =array();
for ($i=0; $i<$length ;$i++){
$temp = $str[array_rand($str)];
$str_r[count($str_r)] = $temp[array_rand($temp)];
}
return($str_r);
}
?>