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);
}
?>

ランダム文字列

ランダム文字列


結果
18439|kC-EU6_n_Ki||admin|admin_password||1|0
18440|34L95b28gAj||admin|admin_password||1|0
18441|i1U9_95_O2_||admin|admin_password||1|0
18442|NvNl-WklsLm||admin|admin_password||1|0
18443|NwG1_F1-H7n||admin|admin_password||1|0
18444|S--7z5-m7_-||admin|admin_password||1|0
18445|re02t7Z-yXq||admin|admin_password||1|0
18446|sN487lP8_-5||admin|admin_password||1|0
18447|GJo9l_4MN-M||admin|admin_password||1|0
18448|nav-HcE9M3H||admin|admin_password||1|0
18449|w--bl6n1Lh_||admin|admin_password||1|0
18450|-5269e50Hb2||admin|admin_password||1|0
18451|l-71gTkJeSh||admin|admin_password||1|0
18452|G38Pz0Nn21M||admin|admin_password||1|0
18453|-A-A67Hnq1W||admin|admin_password||1|0
18454|1pw890B6X_3||admin|admin_password||1|0
18455|t_Qxo_59nj-||admin|admin_password||1|0
18456|97u7_7B5_qg||admin|admin_password||1|0


Github
https://raw.githubusercontent.com/kankanla/Function/master/rand_uniqid.php



<?php
set_time_limit(0);

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

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




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

?>



その2

<?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);
}
?>



2015年8月6日木曜日

Google にアプリケーションIDの取得サイト

Google にアプリケーションIDの取得サイト

https://appengine.google.com/
https://console.developers.google.com/project