개발 & 계발/PHP
-
PHP로 JSON API 서버 만들 때에 index.php 없이 서버 URL 만드는 Apache 설정 방법개발 & 계발/PHP 2023. 10. 21. 15:48
Client가 서버 API 호출을 할 때에 http://{서버}/api/data/dc 와 같은 URL인 경우 PHP는 기본적으로 http://{서버}/api/data/dc.php 처럼 .php이 붙는 상태로 호출을 하기 때문에 다른 Nginx + Django와 같은 다른 웹 서비스를 이용해야 하나 하는 고민이 있었다. 이 경우 Apache의 설정으로도 http://{서버}/api/data/dc 와 같이 사용할 수 있고, 이 때에 api는 폴더이고 api 폴더에 index.php가 응답을 하는 구조이다. 해결책을 제시하기 전에 Apache의 설정 값을 바꾸지 않고 패킷을 캡쳐한 결과 서버가 Client에 "HTTP/1.1 301 Moved Permanently" 라는 메시지를 응답하고, Client는 GE..
-
PHP EXPECT 설치 (at 라즈베리파이)개발 & 계발/PHP 2020. 6. 20. 18:56
안녕하세요! 제가 최근 라즈베리파이에서 PHP를 설치해서 이것저것 해보고 있는데요~ 오늘은 OS에 설치된 SSH, telnet 등을 활용하여 원격 서버 접속하기 위한 "EXPECT" 모듈을 설치해 보겠습니다. expect란? (출처 : https://ko.wikipedia.org/wiki/Expect) Expect는 Don Libes 가 개발한 Tcl 스크립팅 언어의 확장 기능으로서 터미널 인터페이스를 노출하는 프로그램과의 상호작용을 자동화하기 위한 프로그램이다. Expect는 텔넷, 파일 전송 프로토콜, passwd, fsck, rlogin, tip, SSH와 같은 상호작용 응용 프로그램의 제어를 자동화하기 위해 사용된다. Expect는 의사 터미널(유닉스)을 사용하거나 콘솔을 에뮬레이트(윈도우)하고 ..
-
PHP 소켓 서버 만들기!개발 & 계발/PHP 2018. 12. 4. 14:55
출처: http://cometkorea.tistory.com/75 [Comet's library]
-
-
IP 주소 변환 소스개발 & 계발/PHP 2018. 4. 25. 01:30
$ip_str = "192.168.2.100/27";$arr = get_ipaddr_info($ip_str);print_r($arr);function get_ipaddr_info($ip_str){ $result_arr = array(); $result_arr["result"] = "fail"; if(!strstr($ip_str,"/")) return $result_arr; $result_arr["result"] = "success"; $result_arr["ip_str"] = $ip_str; $temp = explode("/", $ip_str); $ip = trim($temp[0]); $cidr = trim($temp[1]); $result_arr["ip"] = $ip; $result_arr["ci..
-
[PHP] AJAX 크로스 도메인 통신 ACCESS-CONTROL-ALLOW-ORIGIN 문제해결개발 & 계발/PHP 2017. 10. 12. 11:36
localhost 에서 다른 서버에 있는 PHP 파일을 호출할 때에 No 'Access-Control-Allow-Origin' header is present on the requested resource와 같은 오류 메시지가 나온다 (크롬에서 확인) 서버 쪽 소스에 아래와 같이 추가해 줘야 한다. header('Access-Control-Allow-Origin: *');header('Access-Control-Allow-Methods: GET, POST, PUT');header("Access-Control-Allow-Headers: X-Requested-With, Content-Type"); 참고 : http://www.planactor.com/?p=419
-
[PHP] timeout이 있는 shell_exec 만들기개발 & 계발/PHP 2015. 1. 12. 13:47
function shell_exec_timeout($cmd, $timeout) { if(!$cmd || !$timeout) return NULL; // File descriptors passed to the process. $descriptors = array( 0 => array('pipe', 'r'), // stdin 1 => array('pipe', 'w'), // stdout 2 => array('pipe', 'w') // stderr ); // Start the process. $process = proc_open($cmd, $descriptors, $pipes); if (!is_resource($process)) { throw new Exception('Could not execute proc..
-
CURL & fsockopen 업무 향상을 위한 샘플개발 & 계발/PHP 2014. 9. 15. 15:24
$ch = curl_init(); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_RETURNTRANSFER,TRUE); curl_setopt($ch, CURLOPT_URL, $oriUrl); curl_setopt($ch, CURLOPT_REFERER, $refUrl); curl_setopt($ch, CURLOPT_HEADER, FALSE); curl_setopt($ch, CURLOPT_USERAGENT, "User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NE..
-
[PHP] preg_match 등 정규식 만들때 사용되는 Pattern Modifier 자료개발 & 계발/PHP 2014. 8. 18. 09:13
출처 : http://php.net/manual/en/reference.pcre.pattern.modifiers.php Pattern Modifiers¶ The current possible PCRE modifiers are listed below. The names in parentheses refer to internal PCRE names for these modifiers. Spaces and newlines are ignored in modifiers, other characters cause error. i (PCRE_CASELESS) If this modifier is set, letters in the pattern match both upper and lower case letters. ..
-
[PHP] FTP_PUT 사용 방법개발 & 계발/PHP 2014. 6. 20. 11:50
출처 : http://us1.php.net/manual/en/function.ftp-put.php
-
배열에 해당 키가 있는지 확인 함수 - (bool) array_key_exists()개발 & 계발/PHP 2014. 4. 28. 20:36
배열 안에 내가 찾는 키가 있는지 확인하기 위해서는 다음과 같은 함수를 사용하면 된다. bool array_key_exists ( mixed key, array search) $arr = array(); $arr["name"] = "SEO"; $arr["phone"] = "02-121-4244"; if(array_key_exists("name",$arr)) // TRUE if(array_key_exists("address",$arr)) // FALSE
-
대용량 파일 필드별 문자열 최대 길이 확인개발 & 계발/PHP 2014. 4. 21. 10:18
$fp = fopen("파일명","r"); $maxlen = array();while(!feof($fp)){ $line = fgets($fp,4096); $temp = explode("\t",$line); for($a = 0 ; $a { if(strlen($temp[$a]) > $maxlen[$a]) { $maxlen[$a] = strlen($temp[$a]); } // if(strlen($temp[$a]) > $maxlen[$a]) } // for($a = 0 ; $a } // while(!feof($fp)) print_r($maxlen);fclose($fp);?>
-