연감이 정상 저장되지 않는 문제 해결

This commit is contained in:
2018-01-31 20:41:36 +09:00
parent c333d397ee
commit 53c63a98bd
2 changed files with 38 additions and 30 deletions
+20 -12
View File
@@ -1,4 +1,5 @@
<?
<?php
require_once('../e_lib/util.php');
include "func_http.php";
function getHistory($count, $year, $month, $isFirst=0) {
@@ -34,7 +35,7 @@ function getGenHistory($count, $year, $month, $isFirst=0) {
@fseek($fp, -$count*300, SEEK_END);
$file = @fread($fp, $count*300);
@fclose($fp);
$log = explode("\r\n",$file);
$log = explode("\n",$file);
$str = "";
$prefix = "</>{$month}월:";
@@ -72,17 +73,25 @@ function LogHistory($connect, $isFirst=0) {
$admin['month'] = 12;
}
$file = explode('/', __FILE__);
$url = '/'.$file[count($file)-3].'/'.$file[count($file)-2].'/map.php?type=2&graphic=0';
//TODO: 웹 접속이 아닌 콘솔일 경우에 대응책 필요. conf등에 저장하는 것을 고려
$current_url = util::get_current_url();
$map_path = explode('/',parse_url($current_url, PHP_URL_PASS));
array_pop($map_path);
array_push($map_path, 'map.php?type=2&graphic=0');
$map_path = join('/', $map_path);
//$file = explode('/', __FILE__);
//$url = '/'.$file[count($file)-3].'/'.$file[count($file)-2].'/map.php?type=2&graphic=0';
/* 소켓 통신을 통하여 필요한 html정보를 가져옴 */
if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', Start HTTP');
$http = new HTTP("62che.com", 80, 10);
//$http = new HTTP("62che.com", 80, 10);
$http = new HTTP(parse_url($current_url, PHP_URL_HOST), parse_url($current_url, PHP_URL_PORT), 10);
if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', Connect end, '.$http->GetError());
if($http->GetErr() == true) { return false; }
$http->setHttpVersion("1.1");
$cookie = "";
$http->Get($url, $cookie);
$http->Get($map_path, $cookie);
if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', Response end, '.$http->GetError());
if($http->GetErr() == true) { return false; }
$map = $http->Response["body"];
@@ -105,13 +114,13 @@ function LogHistory($connect, $isFirst=0) {
for($i=0; $i < $nationcount; $i++) {
$nation = MYDB_fetch_array($result);
$query = "select city from city where nation='$nation[nation]'";
$query = "select city from city where nation='{$nation['nation']}'";
$cityresult = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
$citycount = MYDB_num_rows($cityresult);
$nationStr .= "<font color=cyan>◆</font> <font style=color:".newColor($nation[color]).";background-color:$nation[color];>$nation[name]</font><br>";
$powerStr .= "국력 $nation[power]<br>";
$genStr .= "장수 $nation[gennum]<br>";
$nationStr .= "<font color=cyan>◆</font> <font style=color:".newColor($nation['color']).";background-color:{$nation['color']};>{$nation['name']}</font><br>";
$powerStr .= "국력 {$nation['power']}<br>";
$genStr .= "장수 {$nation['gennum']}<br>";
$cityStr .= "속령 $citycount<br>";
}
@@ -121,11 +130,10 @@ function LogHistory($connect, $isFirst=0) {
insert into history (
year, month, map, log, genlog, nation, power, gen, city
) values (
'$admin[year]', '$admin[month]', '$map', '$log', '$genlog', '$nationStr', '$powerStr', '$genStr', '$cityStr'
'{$admin['year']}', '{$admin['month']}', '$map', '$log', '$genlog', '$nationStr', '$powerStr', '$genStr', '$cityStr'
)",
$connect) or Error(__LINE__.MYDB_error($connect),"");
if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', LogHistory Finish');
return true;
}
?>
+18 -18
View File
@@ -1,4 +1,4 @@
<?
<?php
class HTTP{
var $Socket, $Server, $Port, $Timeout, $HttpVersion = "1.0", $Url, $Length, $ResponseTime, $ErrNum, $ErrMsg;
var $headers = array();
@@ -29,7 +29,7 @@ class HTTP{
$this->Url = $Url;
$msg = sprintf("HEAD %s HTTP/%s\r\n", $this->Url, $this->HttpVersion);
$msg .= $this->PutHead();
$msg .= "\n\n";
$msg .= "\r\n\r\n";
fputs($this->Socket, $msg);
return $this->Read();
@@ -42,7 +42,7 @@ class HTTP{
$msg .= $this->PutCookie($Cookie);
}
$msg .= $this->PutHead();
$msg .= "\n\n";
$msg .= "\r\n\r\n";
fputs($this->Socket, $msg);
return $this->isOK();
@@ -52,7 +52,7 @@ class HTTP{
$this->Url = $Url;
$msg = sprintf("GET %s HTTP/%s\r\n", $this->Url, $this->HttpVersion);
$msg .= $this->PutHead();
$msg .= "\n\n";
$msg .= "\r\n\r\n";
fputs($this->Socket, $msg);
$out = $this->ReadHeader();
return $out;
@@ -65,7 +65,7 @@ class HTTP{
$msg .= $this->PutCookie($Cookie);
}
$msg .= $this->PutHead();
$msg .= "\n\n";
$msg .= "\r\n\r\n";
fputs($this->Socket, $msg);
return $this->Read();
}
@@ -77,7 +77,7 @@ class HTTP{
$msg .= $this->PutCookie($Cookie);
}
$msg .= $this->PutHead();
$msg .= "\n\n";
$msg .= "\r\n\r\n";
fputs($this->Socket, $msg);
return $this->isOK();
}
@@ -89,7 +89,7 @@ class HTTP{
$msg .= $this->PutCookie($Cookie);
}
$msg .= $this->PutHead();
$msg .= "\n\n";
$msg .= "\r\n\r\n";
fputs($this->Socket, $msg);
$data = $this->Read();
@@ -99,39 +99,39 @@ class HTTP{
function Post($Url, $Data, $Cookie = ""){
$this->Url = $Url;
fputs ($this->Socket,sprintf("POST %s HTTP/%s\r\n", $this->Url, $this->HttpVersion));
fputs($this->Socket,sprintf("POST %s HTTP/%s\r\n", $this->Url, $this->HttpVersion));
if($Cookie != ""){
$this->PutCookie($Cookie);
}
$this->PutHead();
fputs ($this->Socket, "Content-type: application/x-www-form-urlencoded\r\n");
fputs($this->Socket, "Content-type: application/x-www-form-urlencoded\r\n");
$out = "";
while (list ($k, $v) = each ($Data)) {
if(strlen($out) != 0) $out .= "&";
$out .= rawurlencode($k). "=" .rawurlencode($v);
}
fputs ($this->Socket, "Content-length: ".strlen($out)."\n\n");
fputs ($this->Socket, "$out");
fputs ($this->Socket, "\n");
fputs($this->Socket, "Content-length: ".strlen($out)."\r\n");
fputs($this->Socket, "$out");
fputs($this->Socket, "\r\n");
return $this->Read();
}
function IsPost($Url, $Data, $Cookie = ""){
$this->Url = $Url;
fputs ($this->Socket,sprintf("POST %s HTTP/%s\r\n", $this->Url, $this->HttpVersion));
fputs($this->Socket,sprintf("POST %s HTTP/%s\r\n", $this->Url, $this->HttpVersion));
if($Cookie != ""){
$this->PutCookie($Cookie);
}
$this->PutHead();
fputs ($this->Socket, "Content-type: application/x-www-form-urlencoded\r\n");
fputs($this->Socket, "Content-type: application/x-www-form-urlencoded\r\n");
$out = "";
while (list ($k, $v) = each ($Data)) {
if(strlen($out) != 0) $out .= "&";
$out .= rawurlencode($k). "=" .rawurlencode($v);
}
fputs ($this->Socket, "Content-length: ".strlen($out)."\n\n");
fputs ($this->Socket, "$out");
fputs ($this->Socket, "\n");
fputs($this->Socket, "Content-length: ".strlen($out)."\r\n\r\n");
fputs($this->Socket, "$out");
fputs($this->Socket, "\r\n");
return $this->isOk();
}
@@ -173,6 +173,7 @@ class HTTP{
$chunked = isset($this->Response['transfer-encoding']) && ('chunked' == $this->Response['transfer-encoding']);
$gzipped = isset($this->Response['content-encoding']) && ('gzip' == $this->Response['content-encoding']);
$body = '';
$this->_chunkLength = 0;
while(!feof($this->Socket)){
if ($chunked) {
$buf = $this->_readChunked();
@@ -285,4 +286,3 @@ class HTTP{
}
}
}
?>