Posted
Filed under PHP
/*동일 아이피 중복 체크_start() */
  $sql = "select count(*) as cnt from $g4[member_table] where mb_ip='$_SERVER[REMOTE_ADDR]'";
  $row = sql_fetch($sql);
  if($row[cnt]>0) alert("이미 동일IP로 가입되어있습니다.");
  /*동일 아이피 중복 체크_end() */
2012/01/24 16:11 2012/01/24 16:11
Posted
Filed under PHP

서버상태 : apm 사용 (apache2.2 php5 mysql5)

내용 : 로컬개발시 도메인에 '_'가 들어갈경우 세션이 무한정 생성되는 문제가 있다.

도메인에 '_'를 사용하지 말자!

2011/11/07 21:09 2011/11/07 21:09
Posted
Filed under PHP
//적용할 게시판명을 넣어 주세요.
$table_names ="forum";
//테이블명을만들고
$bo_table_names ="".$g4[write_prefix]."".$table_names."";
//새글등록후 24시간 전에는 글쓰기를 못하며 시간변경은 (60 * 60 * 24) 부분에서 수정합니다.
$udatatime = date("Y-m-d H:i:s", time() - (int)(60 * 60 * 24));
//지정한 게시판에서 수정은 가능하고 관리자는 제한이 없고 회원일 경우만 체크
if(($member[mb_id] && !$is_admin && $w != "u") && $bo_table == $table_names){
//코멘트 종류와 답글종류는 전부 제외하고 원글만 오늘 올라온글이 있는지
$ab_boards =mysql_fetch_array(mysql_query("select count(*) from $bo_table_names where wr_is_comment ='0' and wr_reply ='' and wr_datetime >= '$udatatime'"));
$rowmembers =$ab_boards[0];
// 오늘올라온 글이 1개라도 존재 한다면
if($rowmembers > 0){
  alert("이게시판에 오늘 $rowmembers 개의 글이 등록이 되었으므로 \\n오늘은 글쓰기를 하실수가 없으며 코멘트만 가능합니다.");
 }
}


[원문 ] http://www.sir.co.kr/bbs/board.php?bo_table=g4_tiptech&wr_id=2100&sca=&sfl=wr_subject%7C%7Cwr_content&stx=%C3%DF%C3%B5+%C0%CC%B5%BF&sop=and
2011/08/11 17:04 2011/08/11 17:04
Posted
Filed under PHP

<?php
$url = “http://pwnthecode.org/home/feed”;
$rss = simplexml_load_file($url);
if($rss)
{
echo ‘<h1>’.$rss->channel->title.’</h1>’;
echo ‘<li>’.$rss->channel->pubDate.’</li>’;
$items = $rss->channel->item;
foreach($items as $item)
{
$title = $item->title;
$link = $item->link;
$published_on = $item->pubDate;
$description = $item->description;
echo ‘<h3><a href=”‘.$link.’”>’.$title.’</a></h3>’;
echo ‘<span>(‘.$published_on.’)</span>’;
echo ‘<p>’.$description.’</p>’;
}
}
?>

2011/08/08 17:19 2011/08/08 17:19
Posted
Filed under PHP
function cqstr($string){
 return rawurlencode( iconv( "CP949", "UTF-8", $string ) )
}
2011/07/26 14:25 2011/07/26 14:25
Posted
Filed under PHP
http://www.barelyfitz.com/projects/csscolor/

CSS Colors: Take Control Using PHP

Neo: Do you always look at it encoded?
Cypher: Well, you have to ... there's way too much information.

While many web sites use powerful programming environments to create HTML, these same tools are usually ignored when it comes to creating Cascading Style Sheets (CSS). This article describes how to take control of your colors in CSS using PHP. You will learn how to:

  • Centralize your color definitions using variables.
  • Separate presentation and content by referring to colors using abstract names such as base and highlight.
  • Automatically generate a color gradient from a single base color:
    -5
    -4
    -3
    -2
    -1
    0
    +1
    +2
    +3
    +4
    +5
  • Automatically adjust the contrast of foreground colors so they can viewed on top of your background colors:
    -5
    -4
    -3
    -2
    -1
    0
    +1
    +2
    +3
    +4
    +5

Using PHP to Generate CSS

To use PHP in your CSS file:

  1. Rename your style.css file to style.php, then add the following to the top of the file:
    <?php header("Content-type: text/css"); ?>

    This line tells the browser that the file is CSS instead of HTML.

  2. In your HTML files, change the stylesheet references from style.css to style.php. For example:
    <link rel="stylesheet" type="text/css"
     media="screen" href="style.php">
    

Centralizing Your Color Definitions

I don't even see the code. All I see is blonde... brunette... redhead...

In a typical CSS file, color codes are scattered throughout the page, and the same colors are used in multiple places. Unless you have a talent for visualizing hex color codes, it can be hard to determine which colors belong to which codes.

Our first goal is to name the color codes and define them in a central location. Then if we want to change a color, we can change it once and the change will be propagated throughout the stylesheet.

Let's start with the following sample stylesheet:

body {
 background:#fff;
 color:#333;
}
h1, h2, h3, h4 {
 color:#00840;
}
blockquote {
 color:#008400;
}

And transform it into this:

<?php
header("Content-type: text/css");
$white = '#fff';
$dkgray = '#333';
$dkgreen = '#008400';
?>
body {
 background:<?=$white?>;
 color:<?=$dkgray?>;
}
h1, h2, h3, h4 {
 color:<?=$dkgreen?>;
}
blockquote {
 color:<?=$dkgreen?>;
}

Abstracting Your Colors

Try to realize the truth... there is no spoon.

What if we wanted to make our headings red? If we changed the value of $dkgreen, then the variable name would not reflect the actual color. Furthermore, if we change $dkgreen, both the heading elements and the blockquote element would change color.

We need to change the way we name our colors, and create variables according to the function of the color instead of the value of the color:

<?php
header("Content-type: text/css");
$pageBG = '#fff';
$pageFG = '#333';
$heading = '#a00000'
$quote = '#008400';
?>
body {
 background:<?=$pageBG?>;
 color:<?=$pageFG?>;
}
h1, h2, h3, h4 {
 color:<?=$heading?>;
}
blockquote {
 color:<?=$quote?>;
}

For a more complex, real-word example, read my Case Study: Abstracting Colors for Hewlett-Packard Company.

Generating Palettes With PHP

We're supposed to start with these operation programs first. That's major boring shit. Let's do something a little more fun.

Now let's take this a step further, and use PHP to generate new colors. We'll start with a base color and a highlight color, then generate a palette of lighter and darker shades:

-5
-4
-3
-2
-1
0
+1
+2
+3
+4
+5
-5
-4
-3
-2
-1
0
+1
+2
+3
+4
+5

Notice that the text is not readable on some of the swatches. Let's use PHP to adjust the foreground color, using color visibility guidelines recommended by the W3C:

-5
-4
-3
-2
-1
0
+1
+2
+3
+4
+5
-5
-4
-3
-2
-1
0
+1
+2
+3
+4
+5

To define these colors in our CSS file, simply add the following lines:

<?php
include_once("csscolor.php");
$base = new CSS_Color('C9E3A6');
$highlight = new CSS_Color('746B8E');
?>

Then to use the colors, do something like this:

/* Use the base color, two shades darker */
background:#<?= $base->bg['-2'] ?>;

/* Use the corresponding foreground color */
color:#<?= $base->fg['-2'] ?>;

/* Use the highlight color as a border */
border:5px solid #<?= $highlight->bg['0'] ?>

Here is an example of the style in action.

Download

You can download csscolor.php here:


2011/07/09 14:00 2011/07/09 14:00
Posted
Filed under PHP
[원문] - http://www.emanueleferonato.com/2009/09/23/mysql-to-json-with-php/
function mysql2json($mysql_result,$name){
     $json="{\n\"$name\": [\n";
     $field_names = array();
     $fields = mysql_num_fields($mysql_result);
     for($x=0;$x<$fields;$x++){
          $field_name = mysql_fetch_field($mysql_result, $x);
          if($field_name){
               $field_names[$x]=$field_name->name;
          }
     }
     $rows = mysql_num_rows($mysql_result);
     for($x=0;$x<$rows;$x++){
          $row = mysql_fetch_array($mysql_result);
          $json.="{\n";
          for($y=0;$y<count($field_names);$y++) {
               $json.="\"$field_names[$y]\" : \"$row[$y]\"";
               if($y==count($field_names)-1){
                    $json.="\n";
               }
               else{
                    $json.=",\n";
               }
          }
          if($x==$rows-1){
               $json.="\n}\n";
          }
          else{
               $json.="\n},\n";
          }
     }
     $json.="]\n};";
     return($json);
} function mysql2json($mysql_result,$name){
     $json="{\n\"$name\": [\n";
     $field_names = array();
     $fields = mysql_num_fields($mysql_result);
     for($x=0;$x<$fields;$x++){
          $field_name = mysql_fetch_field($mysql_result, $x);
          if($field_name){
               $field_names[$x]=$field_name->name;
          }
     }
     $rows = mysql_num_rows($mysql_result);
     for($x=0;$x<$rows;$x++){
          $row = mysql_fetch_array($mysql_result);
          $json.="{\n";
          for($y=0;$y<count($field_names);$y++) {
               $json.="\"$field_names[$y]\" : \"$row[$y]\"";
               if($y==count($field_names)-1){
                    $json.="\n";
               }
               else{
                    $json.=",\n";
               }
          }
          if($x==$rows-1){
               $json.="\n}\n";
          }
          else{
               $json.="\n},\n";
          }
     }
     $json.="]\n};";
     return($json);
}
2011/06/21 08:01 2011/06/21 08:01
Posted
Filed under PHP

간단하게 페이징 클래스를 만들어 보았다.
class_paging.php 파일은 PHP4/5 모두 사용가능하며 일반적인 클래스 작성방식으로 작성했으며
class_paging_php5.php 파일은 PHP5 버젼에서 사용가능하며 Singleton 방식으로 작성되어 있다.
사용예제

<style> .aaa {font-family: "돋움","굴림";font-size: 11px ;color: #FF7E00; font-weight : bold;} .bbb {font-family: "돋움","굴림";font-size: 12px ;color: red; font-weight : bold;} </style> <?php require "class_paging.php"; $page = $_GET['page']; $params = array( 'curPageNum' => $page, 'pageVar' => 'page', 'extraVar' => '&aaa=1&bbb=abc', 'totalItem' => 176, 'perPage' => 10, 'perItem' => 5, 'prevPage' => '[이전]', 'nextPage' => '[다음]', 'prevPerPage' => '[이전10페이지]', 'nextPerPage' => '[다음10페이지]', 'firstPage' => '[처음]', 'lastPage' => '[끝]', 'pageCss' => 'aaa', 'curPageCss' => 'bbb' ); $paging = new YsPaging($params); $paging->printPaging(); ?>

$params 설명 (필수옵션)

curPageNum : 현재 페이지의 값을 넘겨 줍니다.
pageVar : 페이지 링크에 사용할 변수명(ex page,pagenum)
extraVar : 페이지 링크에 추가적으로 같이 넘길 변수 link를 기입(ex "&opt1=10&opt2=가나다")
totalItem : 데이타베이스에 읽어들인 글(아이템)의 총 수
perPage : 페이지 리스트 링크에 몇개씩 리스트를 뿌릴 것인지 (ex 5 설정하면 페이지리스트에 1 2 3 4 5가 나옴)
perItem : 한페이지에 뿌려지는 글(아이템)의 수(실제 리스팅은 select 쿼리에서 하시고 이옵션은 페이지 계산용)
prevPage : "이전" 링크에 사용할 문구나 이미지 태그 미설정시 "이전"이 출력
nextPage : "다음" 링크에 사용할 문구나 이미지 태그 미설정시 "다음"이 출력
prevPerPage : "이전10개" 링크에 사용할 문구나 이미지 태그 미설정시 출력 안됨
nextPerPage : "다음10개" 링크에 사용할 문구나 이미지 태그 미설정시 출력 안됨
firstPage : "처음" 링크에 사용할 문구나 이미지 태그 미설정시 출력 안됨
lastPage : "마지막" 링크에 사용할 문구나 이미지 태그 미설정시 출력 안됨
pageCss : 페이지 목록 링크에서 사용할 스타일 시트
curPageCss : 페이지 목록 링크 중 현재 페이지 번호에서 사용할 스타일 시트



참고
class_paging_php5.php 파일의 경우
$paging = YsPaging::getInstance($params);
를 사용하면 싱글톤으로 구현됩니다.

페이지 링크에 관한 구성은 printPaging() 메소드를 상속후 오버라이딩하거나
개별 메소드를 호출하여 구성하여도 됩니다.

echo $paging->getFirstPage();
echo $paging->getPrevPerPage();
echo $paging->getPrevPage();
echo $paging->getPageList();
echo $paging->getNextPage();
echo $paging->getNextPerPage();
echo $paging->getLastPage();

[원문] - http://wyseburn.tistory.com/107

2011/05/26 14:04 2011/05/26 14:04
Posted
Filed under PHP
<?php

$size = getimagesize("./Forest Flowers.jpg");
print_r($size);

?>

출력 :
Array
(
   [0] => 1024
   [1] => 768
   [2] => 2
   [3] => width="1024" height="768"
   [bits] => 8
   [channels] => 3
   [mime] => image/jpeg
)

위의 예제에서도 알수 있듯이
$size[0] 에는 이미지의 너비
$size[1] 에는 이미지의 높이
$size[2] 에는 이미지의 타입
$size[3] 에는 html로 출력시 img 태그에 넣을 요소
$size['mime'] 에는 이미지의 mimetype
2011/04/06 05:59 2011/04/06 05:59
Posted
Filed under PHP
http://홈주소/?mode=xxx 하는방법 :)
http://홈주소/?exec=xxx 같은걸 보면 괜히 폼나고 그렇죠;;

저거는요 먼저 계정을 제공하는곳에서요 index.php나 이런 종류의 인덱스 파일을 인식해야 됩니다^-^;

index.php 란 파일이 있습니다
내용은 :
<?

switch ($mode) {
    case  "php" :
    case  "freeboard" :
        $id=$mode;
        include_once ("./board/list.php");
        break;
    case  "zeni" :
        include_once ("./$mode.zeni");
        break;
    case  "homework" :
        include_once ("./study.php");
        break;
    default :
    echo("잘못 호출 하셧습니다 :) ");
    exit;
}
?>

이런 내용이 있다구 치구요 부를때에는 index.php?mode=xxx 라고 부르면 되는걸로 알고 있을겁니다
그렇지만 계정에서

http://홈주소/

라고 쳤을때 만약 http://홈주소/index.php 파일에 내용이 뜰경우

그냥 http://홈주소/?mode=xxx 해주시면 됩니다

너무 쉬운 강좌인가요? 예를 보여드리겠습니다;
http://netmask.co.kr/~zeni/?mode=notice
이런 형식으로 보여지게 됩니다 ^-^;

[원문 ] :http://sir.co.kr/bbs/board.php?bo_table=pg_php&wr_id=1282&sca=&sfl=wr_subject&stx=%EC%A3%BC%EC%86%8C&sop=and
2011/03/05 16:04 2011/03/05 16:04