<code><span><span><?php</span><span>namespace</span><span>Addons</span>\<span>Coupon</span>\<span>Controller</span>; <span>use</span><span>Home</span>\<span>Controller</span>\<span>AddonsController</span>; <span><span>class</span><span>WapController</span><span>extends</span><span>AddonsController</span>{</span><span>protected</span><span>$model</span>; <span>public</span><span><span>function</span><span>__construct</span><span>()</span> {</span><span>$GLOBALS</span> [<span>'is_wap'</span>] = <span>true</span>; <span>parent</span>::__construct (); <span>$uid</span>= get_uid_by_openid(); <span>$this</span>->model = getModelByName (<span>'coupon'</span>); <span>$this</span>->model || <span>$this</span>->error ( <span>'model is not found!'</span> ); } <span>/* * Create coupon code * *<span> @param</span> $namespace string *<span> @return</span> $guid string *<span> @author</span> sun */</span><span>private</span><span><span>function</span><span>create_guid</span><span>(<span>$namespace</span> = <span>''</span>)</span> {</span><span>static</span><span>$guid</span> = <span>''</span>; <span>$uid</span> = uniqid(<span>""</span>, <span>true</span>); <span>$data</span> = <span>$namespace</span>; <span>$data</span> .= <span>$_SERVER</span>[<span>'REQUEST_TIME'</span>]; <span>$data</span> .= <span>$_SERVER</span>[<span>'HTTP_USER_AGENT'</span>]; <span>$data</span> .= <span>$_SERVER</span>[<span>'LOCAL_ADDR'</span>]; <span>$data</span> .= <span>$_SERVER</span>[<span>'LOCAL_PORT'</span>]; <span>$data</span> .= <span>$_SERVER</span>[<span>'REMOTE_ADDR'</span>]; <span>$data</span> .= <span>$_SERVER</span>[<span>'REMOTE_PORT'</span>]; <span>$hash</span> = strtoupper(hash(<span>'ripemd128'</span>, <span>$uid</span> . <span>$guid</span> . md5(<span>$data</span>))); <span>// test str combination</span><span>$guid</span> = substr(<span>$hash</span>, <span>0</span>, <span>6</span>) . <span>'-'</span> . substr(<span>$hash</span>, <span>8</span>, <span>4</span>) . <span>'-'</span> . substr(<span>$hash</span>, <span>12</span>, <span>4</span>) . <span>'-'</span> . substr(<span>$hash</span>, <span>16</span>, <span>4</span>) . <span>'-'</span> . substr(<span>$hash</span>, <span>20</span>, <span>8</span>); <span>return</span><span>$guid</span>; } } <span>// end</span></span></span></code>').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });
위 내용은 PHP/THINKPHP로 쿠폰 코드를 생성하는 방법을 소개하고 있으며, PHP 튜토리얼에 관심이 있는 친구들에게 도움이 되기를 바랍니다.