2010년 2월 9일 화요일
[PHP] CSV 파일 DB에 입력하는 소스
http://kin.naver.com/qna/detail.nhn?d1id=1&dirId=1040203&docId=71861876&qb=cGhwIOyXkeyFgCBkYiDsnoXroKU=&enc=utf8§ion=kin&rank=1&sort=0&spq=0&pid=f3vGtdoi5TVsssPXPBVsss
--028753&sid=S2-1DMDeb0sAAGxfNa8
윈도기반 오피스가 깔려있고, 윈도우서버를 이용시
PHP로 엑셀 -> DB 입력방법 혹은 DB->엑셀로 추출
http://www.phpschool.com/gnuboard4/bbs/board.php?bo_table=tipntech&wr_id=70906
2010년 1월 27일 수요일
[PHP] 폼메일 전송시 한글 깨짐 현상 해결방법
$charset='UTF-8'; // 문자셋 : UTF-8
$subject=$subject; // 제목
$toName='홍길동'; // 받는이 이름
$toEmail= $to; // 받는이 이메일주소
$fromName=$cok_name; // 보내는이 이름
$fromEmail=$cok_mail; // 보내는이 이메일주소
$body=$content; // 메일내용
$body = iconv('utf-8', 'euc-kr', $body); //본문 내용 UTF-8화
$encoded_subject="=?".$charset."?B?".base64_encode($subject)."?=\n"; // 인코딩된 제목
$to= "\"=?".$charset."?B?".base64_encode($toName)."?=\" <".$toEmail.">" ; // 인코딩된 받는이
$from= "\"=?".$charset."?B?".base64_encode($fromName)."?=\" <".$fromEmail.">" ; // 인코딩된 보내는이
$headers="MIME-Version: 1.0\n".
"Content-Type: text/html; charset=".$charset."; format=flowed\n".
"To: ". $to ."\n".
"From: ".$from."\n".
"Return-Path: ".$from."\n".
"Content-Transfer-Encoding: 8bit\n"; // 헤더 설정
mail( $to , $encoded_subject , $body , $headers ); // 메일 보내기
2010년 1월 26일 화요일
[PHP] PHP로 HTML 폼메일 이메일 전송하기
<?
$name = "이름변수";
$sex = '성별변수';
$email = '보내는 사람 이메일';
$subject = "제목입니다";
$contents = "내용입니다 내용이예요";
$tomail = "lucael@naver.com"; //이 폼메일을 받을 메일주소
function error($text){
echo "
<script language=javascript>
window.alert('$text')
history.go(-1)
</script>";
exit;
}
function msg($text){
echo "
<script language=javascript>
window.alert('$text')
top.location.href = 'http://gogoflow.com/index2.php'
</script>
";
exit;
}
if (!$name) {error('성명을 적어주세요');} // 이름이 없을때 에러 메세지
if (!$sex) {error('성별을 선택해 주세요');}
if (!$email) {error('메일 주소를 적어주세요');} // 메일주소가 없을때 에러 메세지
if (!$subject) {error('제목을 적어주세요');} // 제목이 없을때 에러 메세지
$mailheaders = "Return-Path: $email \r\n"; // 메일 헤더의 반송 메일 주소
$mailheaders .= "From: $name <$email>\r\n"; // 메일헤더의 이름과 메일 주소 표시
$body = " 이름 : $name \r\n";
$body .= " 메일주소 : $email \r\n";
$body .= " 성별 : $sex \r\n";
$body .= " 전화 : $tel \r\n";
$body .= " 내 용 : $content \r\n";
$result=mail($tomail , $subject , $body , $mailheaders); // 메일 전송
if($result) {msg('메일이 성공적으로 발송되었습니다.');} // 전송 성공시
else{error('메일 발송에 실패하였습니다.');} // 전송 실패시
?>
2009년 11월 18일 수요일
[PHP] PHP 를 이용하여 웹페이지를 엑셀파일로 변환하여 다운받기
<a href="/down.php?>">[리스트 다운로드]</a>
===============down.php========================
<?
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=Excel.xls");
header("Content-Description: PHP4 Generated Data");
$sql = "쿼리문입력'";
$stmt = mysql_query($sql, $connect);
$num = mysql_num_rows($stmt);
?>
<meta http-equiv="Content-Type" content="text/html; charset=euc-kr">
<table border="1" cellpadding="1" cellspacing="0">
<tr>
<td><b>NO</b></td>
<td><b>제목</b></td>
<td><b>작성자</b></td>
<td><b>날짜</b></td>
<td><b>조회수</b></td>
</tr>
<?
for($i = 0; $i < $num; $i++)
{
$res = mysql_fetch_array($stmt);
$j++;
echo "<tr><td>$j</td><td>$res[subject]</td><td>$res[name]</td><td>$res[date]</td><td>$res[hit]</td></tr>";
}
flush();
usleep(1);
?>
</table>
2009년 10월 9일 금요일
[PHP] PHP SetCookie 사용법 (쿠키 Cookie)
Examples
Some examples follow how to send cookies:
Example #1 setcookie()>$2 send example
<?php
$value = 'something from somewhere';
setcookie("TestCookie", $value);
setcookie("TestCookie", $value, time()+3600); /* expire in 1 hour */
setcookie("TestCookie", $value, time()+3600, "/~rasmus/", ".example.com", 1);
?> Note that the value portion of the cookie will automatically be urlencoded when you send the cookie, and when it is received, it is automatically decoded and assigned to a variable by the same name as the cookie name. If you don't want this, you can use setrawcookie() instead if you are using PHP 5. To see the contents of our test cookie in a script, simply use one of the following examples:
<?php
// Print an individual cookie
echo $_COOKIE["TestCookie"];
echo $HTTP_COOKIE_VARS["TestCookie"];
// Another way to debug/test is to view all cookies
print_r($_COOKIE);
?> Example #2 setcookie()>$2 delete example
When deleting a cookie you should assure that the expiration date is in the past, to trigger the removal mechanism in your browser. Examples follow how to delete cookies sent in previous example:
<?php
// set the expiration date to one hour ago
setcookie ("TestCookie", "", time() - 3600);
setcookie ("TestCookie", "", time() - 3600, "/~rasmus/", ".example.com", 1);
?> Example #3 setcookie()>$2 and arrays
You may also set array cookies by using array notation in the cookie name. This has the effect of setting as many cookies as you have array elements, but when the cookie is received by your script, the values are all placed in an array with the cookie's name:
<?php
// set the cookies
setcookie("cookie[three]", "cookiethree");
setcookie("cookie[two]", "cookietwo");
setcookie("cookie[one]", "cookieone");
// after the page reloads, print them out
if (isset($_COOKIE['cookie'])) {
foreach ($_COOKIE['cookie'] as $name => $value) {
echo "$name : $value <br />\n";
}
}
?> The above example will output:
three : cookiethree two : cookietwo one : cookieone
2009년 6월 30일 화요일
[PHP] PHP 내 내용을 암호화 혹은 복호화 관련 정보
역시 보안이라면 패스워드가 가장 먼저 떠오르는 만큼...
암호화시에는 mcrypt_encoded
로그인을 해야 볼수 있네;;
http://book.naver.com/bookdb/book_detail.php?bid=2103583&menu=dview&dencrt=YSlJ2RiZBwdnltmRTzBDUllWMGcrTFU0YldjWFRJcUwxZ05BRXlxVGFqSzVuVVR2YXdKdGJJN21iVmE3Vm1DLw==&query=php+%BE%CF%C8%A3+%BA%B9%C8%A3%C8%AD&term=php%20%BE%CF%C8%A3%20%BA%B9%C8%A3%C8%AD%20php%BE%CF%C8%A3%BA%B9%C8%A3%C8%AD#middle_tab
2009년 5월 14일 목요일
[PHP] 암호를 암호화 시켜서 삽입 및 암호화된 암호값 비교하기
// 기존의 내가 코딩하던 방식은 단순히 그냥 폼값에 있는 암호값을 DB에 쿼리를 날려서
// 다이렉트로 비교하던 방식이였고, DB에 저장되있는 암호를 직접 볼수도 있는 상황이였다...
// 즉, DB 관리자 패스워드가 노출이 될경우 사용자 신상정보 모두가 유출될수 있기에 암호를 저장할때도
// 암호화해서 저장하고 비교할때도 암호화해서 비교하는 방식이 기존의 다이렉트 비교방식보다는
// 안전하다고 볼수 있을것 같다.. 대략 아래 소스코드로 비교 및 삽입시 응용할 수 있을듯하다...
// 아래는 비교하기 예제
...
$parr=mysql_fetch_array($psql);
if(!$parr){ alert("비밀번호가 틀렸습니다."); goback(); }
// 아래는 삽입 예제
$parr=mysql_fetch_array($psql);
[PHP] 파일을 읽어서 테이블안에 텍스트 출력하기
//PHP에서 배열변수에 파일함수를 이용해서 파일을 배열에 저장하면...
//아래처럼 인덱스를 이용해서 각줄을 출력할수 있다... 직접 태그로 html파일로 약관 저장해서
//iframe으로 불러들여와서 했었는데.. 어떻게보면 이게 더 간단하고 뭔가 더 간단해보인다랄까...
<td width="600">
if (is_file("./member_agree.dat"))
{
$aarray = file("./member_agree.dat");
for($i = 0; $i < sizeof($aarray); $i++){
echo "".nl2br($aarray[$i])."";
}
}
?>
<td>
2009년 1월 8일 목요일
PHP에서의 JSON파싱 방법
http://mike.teczno.com/json.html 에서 무료로 구할 수 있다.
PHP에서 JSON 객체를 이용하기 위해 필요한 일은 페이지에 JSON.php 파일을 포함시켜서 JSON 객체를 이용하는 것뿐이다.
JSON 객체의 새로운 인스턴스를 생성하는 방법은 아주 간단하다.
<?php
require_once("JSON.php");
$oJSON = new JSON();
?>
==========
ex)
eval("var decoded_data = "+encoded_data); With JSON-PHP, it can be almost as easy on the server-side, too:
ex)
// create a new instance of Services_JSON
require_once('JSON.php');
$json = new Services_JSON();
// convert a complex value to JSON notation
$value = array(1, 2, 'foo');
$output = $json->encode($value);
print($output);
// accept incoming POST data
$input = $GLOBALS['HTTP_RAW_POST_DATA'];
$value = $json->decode($input);