Welcome Guest, you are in: Login

MUST Creative Engineering Laboratory

RSS RSS

Navigation



Technical Doc



Search the wiki
»

MUST Corp.

MUST Corp.

www.must.or.kr

 Microsoft CERTIFIED Partner Software Development, Web Development, Data Platform

 Microsoft Small Business Specialist

MCSD

Microsoft Certified IT Professional

Microsoft Certified Professional Developer

서명(signature) 생성 PHP 샘플코드



here is slight difference between .Net and PHP. While .Net expects byte array as key, PHP expects string as key. Thus we have to form string representing byte array.

예제1

  • 텍스트(t)를 자동 생성코자 할때

<?php
$key = pack('c*', 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff);
$sig = hash_hmac('sha256', "t=HelloWorld&r=10", $key);
echo '<img src="http://mqr.kr/qr/?t=HelloWorld&amp;r=10&amp;sign='.$sig.'"/>';
?>

예제2

  • 현재 날짜 / 시간으로 QR 코드를 생성을위한 PHP 코드 샘플

<?php
$key = pack('c*', 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff);
$text = date('Y.m.d H:i:s');
$query = 't='.urlencode($text).'&r=10&j=1&m=20&lb=fccd13&lt=ed1e2e&rt=155ca2';
$sig = hash_hmac('sha256', $query, $key);
echo '<img src="http://mqr.kr/qr/?'.htmlentities($query).'&amp;sign='.$sig.'"/>';
?>

  • $text 변수에 텍스트를 삽입할 수 있습니다

예제3

  • 홈페이지 현재 URL 정보를 담은 QR코드 자동 생성을위한 PHP 코드 샘플

<?php
function curPageURL() {
 $pageURL = 'http';
 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 $pageURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
 } else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 }
 return $pageURL;
}
?>

<?php
$key = pack('c*', 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff);
$text = curPageURL();
$query = 't='.urlencode($text).'&r=10&j=1&m=20&lb=fccd13&lt=ed1e2e&rt=155ca2';
$sig = hash_hmac('sha256', $query, $key);
echo '<img src="http://mqr.kr/qr/?'.htmlentities($query).'&amp;sign='.$sig.'"/>';
?>

  • PHP에서 현재 URL을 찾아내는것은 찾은결과 이것보다 간단한 방법이 없는듯합니다.

MUST Creative Engineering Laboratory

ImageImage Image Image

Image Image Image Image Image Image Image

Copyright © 2010 MUST Corp. All rights reserved. must@must.or.kr
This Program is released under the GNU General Public License v2. View the GNU General Public License v2 or visit the GNU website.