顯示具有 PHP 標籤的文章。 顯示所有文章
顯示具有 PHP 標籤的文章。 顯示所有文章

2007年7月17日 星期二

呼叫遠端伺服器javascript&php

好久沒發文了
這是用ajax的技術使用javascript
用戶端連結伺服器在以php連結遠端伺服器
最後在傳回用戶端

var xmlHttp = createXmlHttpRequestObject();
var serverAddress = "smartpoxyping.php;
var getNumberParams= "action=GetNumber" + "&min=1"+"&max=100";
var chechAvailabilityParams = "action=checkavailability;
var requestscount=0;
var checkinterval=10;
var updateinterval=1; '等待1秒取得新亂數
var updateintervalifserverbusy=10; '伺服器連線繁忙時等待10秒後重試
var minserverbufferlevel=50;

function createXmlHttpRequestObject()
{
var xmlhttp;
try
{
xmlhttp = new xmlhttprequest();
}
catch(e)
{
var xmlhttpversions = new array("MSXML2.XMLHTTP.6.0","MSXML2.XMLHTTP.5.0","MSXML2.XMLHTTP.4.0","MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP","Microsoft.XmlHTTP");
for (var i=0; itry
{
xmlhttp = new Activexobject(xmlhttpversions[i]);
}
catch(e){}
}
}
if (!xmlhttp)
alert("建立xmlhttprequest物件產生錯誤");
else
reurn xmlhttp;
}

function process()
{
if (xmlhttp)
{
try
{
if (requestscounter % checkinterval==0)
{
xmlhttp.open("GET",serveraddress+ "?" +checkavailabilityparams,true);
xmlhttp.onreadystatechange = handlecheckingavailability;
xmlhttp.send(null);
}
else
{
xmlhttp.open("GET",serveraddress+ "?" +checkavailabilityparams,true);
xmlhttp.onreadystatechange = handlegettingnumber;
xmlhttp.send(null);
}
}
catch(e)
{
alert("無法連結伺服器")
}
}
}

function handlecheckingavailability()
{
if (xmlhttp.readystate ==4)
{
if (xmlhttp.status ==200)
{
try
{
checkavailability();
}
chatch(e)
{
alert("伺服器連結錯誤");
}
}
else
{
alert("伺服器讀取錯誤");
}
}
}

function checkavailability()
{
var response = xmlhttp.responsetext;
if (response.length > 5 || response.length ==0)
throw(response.length ==0 ? "伺服器錯誤" : response);
mydiv = document.getelementbyid("mydivelement");
if(response >= minserverbufferlevel)
{
mydiv.innerHtml += "伺服器緩衝" + respnose + "%, " + "開始接收新數字
";
requestconnter++;
settimeout("process();",updateinterval*1000)
}
else
{
mydiv.innerHtml += "伺服器緩衝" + respnose + "%, " + "將重新檢查
";
settimeout("process();",updateinterval*1000)
}
}

這些為js的程式碼片段
懶的key註解了 = =

2007年7月5日 星期四

使用php與ajax製作xml回傳至客戶端

var xmlhttp =createxmlhttprequestobject();
function createxmlhttprequestobject()
{
var xmlhttp;
try
{
xmlhttp = new xmlhttprequest();
}
catch(e)
{
var xmlhttpversions = new array ("MSXML2.XMLHTTP.6.0","MSXML2.XMLHTTP.5.0","MSXML2.XMLHTTP.4.0","MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP","Microsoft.XMLHTTP");
for (var i=0;i {
try
{
xmlhttp= new activexobject(xmlhttpversions[i]);
}
catch(e){}
}
}
if (!xmlhttp)
alert("error creating the xmlhttprequest object.")
else
return xmlhttp;
}
function process()
{
if (xmlhttp)
{
try
{
xmlhttp.open("GET","phptest.php",true);
xmlhttp.onreadystatechange = handlerequeststatechange;
xmlhttp.send(null);
}
catch(e)
{
alert("can't connect to server: \n" + e.tostring());
}
}
}

function handlerequeststatechange()
{
if(xmlhttp.readystate == 4)
{
try
{
handleserverresponse();
}
catch(e)
{
alert("error reading the response: " + e.tostring());
}
}
else
{
alert("there was a problem retrieving the data:\n" +xmlhttp.statustext);
}
}
function handleserverresponse()
{
var xmlresponse = xmlhttp.responsexml;
if(!xmlresponse || !xmlresponse.documentelement)
throw("invalid xml structre:\n" + xmlhttp.responsetext);
var rootnodename = xmlresponse.documentelement.nodename;
if (rootnodename == "parsererror") throw("invalid xml structure");
xmlroot = xmlresponse.documentelement;
titlearray = xmlroot.getelementsbytagname("title");
isbnarray = xmlroot.getelementsbytagname("isbn");
var html = "";
for (var i=0;i html += titlearray.item(i).firstchild.data + ", " + isbnarray.item(i).firstchild.data + "
";
mydiv=document.getelementbyid("mydivelement");
mydiv.innerhtml = html;
}

2007年6月24日 星期日

PHP 部落格架設 以系統管理者登入時的原碼

最近因為要考試。而且最近做的事情都被不太順利
所以,好幾天才發一個文章
這是之前有發過修改發文的那一個部落格
裡面管理者控制的原碼
< ? PHP
define('VALIDADMIN', 1);
require_once ("global.php");
include_once ("lang/{$langback}/backend.php");
include_once ("data/allmods.php");
include("data/cache_usergroup.php");
require_once ("admin/cache_func.php");

unset($blogplugin);
include_once("data/plugin_enabled.php");


acceptrequest('act,go,page');
if (!isset($page) || !is_numeric($page) || $page<=0) $page=1;
else $page=floor($page);
if ($go) @list($act, $job, $itemid)=@explode('_', basename($go));
if (!$act) $act='main';
else $act=basename($act);

if ($act=='upload') {
include ("admin/cp_upload.php");
exit();
}

$maxrecord=$blog->getsinglevalue("{$db_prefix}maxrec");

include_once("admin/admin_header.php");

if (file_exists("admin/cp_{$act}.php")) include ("admin/cp_{$act}.php");
else {
if (is_file("plugin/{$act}/admin.php")) {
$display_overall.=highlightadminitems('plugin', 'addon');
include ("plugin/{$act}/admin.php");
$display_overall=str_replace('', $plugin_header, $display_overall);
$display_overall=str_replace(' $display_overall.=$plugin_return;
}
else include ("admin/cp_main.php");
}
include_once("admin/admin_footer.php");

function highlightadminitems ($itemhighlight, $itemsrow) {
global $admin_item;
while (@list ($key, $value)=@each($admin_item[$itemsrow])) {
if ($itemhighlight==$key) $addclass='highlight';
else $addclass='normal';
$rollall.="
  • < a href=\"admin.php?go={$itemsrow}_{$key}\">{$value}
  • ";
    }
    return ("
    \n
      {$rollall}
    \n\n
    ");
    }

    function addpref ($pref_type, $pref_content) { //This will generate the complete config form body
    global $pref_leftchar, $pref_variable, $pref_result, $pref_quicksel, $prefseccounter;
    if ($pref_leftchar=='') $pref_leftchar=200;
    global $$pref_variable;
    $prefvalue=$$pref_variable;
    $prefs=@explode("|", $pref_content);
    switch ($pref_type) {
    case 't': //text input
    $output="< tr >< "td" class=\"prefleft\" valign=\"top\" width='$pref_leftchar'>{$prefs[1]} < 'td' class=\"prefright\"><" input type='text' name='prefconfig[{$prefs[0]}]' id='{$prefs[0]}' value=\"". "stripslashes($prefvalue[$prefs[0]])."\" size='40'> {$prefs[2]}< / td >< / tr >";
    break;
    case 'ta': //textarea
    $output="<'td' class=\"prefleft\" valign=\"top\" width='$pref_leftchar'>{$prefs[1]}<"textarea name='prefconfig[{$prefs[0]}]' id='{$prefs[0]}' cols='90' rows='6'>".stripslashes($prefvalue[$prefs[0]])." {$prefs[2]}";
    break;
    case 'r': //radio button
    $check1=($prefvalue[$prefs[0]]==1) ? " checked='checked' " : '';
    $check2=($prefvalue[$prefs[0]]==1) ? '' : " checked='checked' ";
    $output="{$prefs[1]}<"input type='radio' name='prefconfig[{$prefs[0]}]' id='{$prefs[0]}' value='1' {$check1}>{$prefs[3]} {$prefs[2]} {$prefs[4]}";
    break;
    case 'sel': //selection
    $tmp_sel="{$prefs[1]}<"select name='prefconfig[{$prefs[0]}]' id='{$prefs[0]}'>";
    $current_sel_all=@explode("<<", $prefs[2]);
    for ($i=0; $i $current_sel=@explode(">>", $current_sel_all[$i]);
    if ($current_sel[0]==$prefvalue[$prefs[0]]) $seled=" selected";
    else $seled='';
    $tmp_sel.="";
    }
    $tmp_sel.=" {$prefs[3]}";
    $output=$tmp_sel;
    unset($tmp_sel, $current_sel_all);
    break;
    case 'sec': //A separator
    $output="<"a "name=\"pref{$prefseccounter}\">{$prefs[0]} <"a href=\"#top\">[top]";
    if ($prefseccounter%5==0) $pref_quicksel.="";
    $pref_quicksel.="[<"a href=\"#pref{$prefseccounter}\">{$prefs[0]}]";
    if ($prefseccounter%5==4) $pref_quicksel.="";
    $prefseccounter+=1;
    break;
    }
    $pref_result[]=$output;
    }

    function changesingleconfig ($configname, $value, $configtype='mbcon', $configfile='data/mod_config.php') { // Change a single value for config
    global $$configtype, $lnc;
    $rar=$$configtype;
    $rar[$configname]=$value;
    $savetext=" while (@list ($key, $val) = @each ($rar)) {
    $savetext.="\${$configtype}['{$key}']='".safe_convert(stripslashes($val))."';\n";
    }
    if (writetofile ($configfile, $savetext)) {
    return true;
    } else {
    catcherror ($lnc[7].$configfile);
    }
    }

    function replaceblock ($filename, $blockidentifier, $newvalues) { //Partially change the content of a file
    $oldfilecontent=@readfromfile($filename);
    $inthebeginning="//[Start]{$blockidentifier}";
    $intheend="//[End]{$blockidentifier}";
    @list($thebeginningpart, $tobereplaced)=@explode($inthebeginning, $oldfilecontent);
    @list($tobereplaced, $theendpart)=@explode($intheend, $oldfilecontent);
    $newvalues=$inthebeginning."\r\n".$newvalues."\r\n".$intheend."\r\n";
    $newcontent=$thebeginningpart.$newvalues.$theendpart;
    $newcontent=str_replace("\r\n\r\n", "\r\n", $newcontent);
    return writetofile ($filename, $newcontent);
    }

    function mod_append ($value) {
    global $lnc;
    $filename="data/modules.php";
    $filecontent=@readfromfile($filename);
    $value="/*--APPENDAREA--*/\n".$value."\n";
    $filecontent=str_replace("/*--APPENDAREA--*/", $value, $filecontent);
    $filecontent=str_replace("\n\n", "\n", $filecontent);
    if (writetofile ($filename, $filecontent)) {
    return true;
    } else {
    catcherror ($lnc[7].$filename);
    }
    }


    function mod_replace ($name, $value) {
    global $lnc;
    $filename="data/modules.php";
    $filecontent=@file($filename);
    for ($i=0; $i if (strstr($filecontent[$i], "\$blogitem['{$name}']=")) {
    $filecontent[$i]=$value;
    break;
    }
    }
    $newfilecontent=@implode('', $filecontent);
    if (writetofile ($filename, $newfilecontent)) {
    return true;
    } else {
    catcherror ($lnc[7].$filename);
    }
    }

    function gen_page ($page, $numperline, $returnurl, $totalvolume, $perpagevolume) {
    global $lnc;
    $conxer=(strstr($returnurl, '?'))? '&' : '?';
    $total_pages=floor(($totalvolume-1)/$perpagevolume)+1;
    if (empty($total_pages)) return '';
    $firstindexpage=floor($page/$numperline)*$numperline+1;
    $lastindexpage=min(($firstindexpage+$numperline-1), $total_pages);
    $pagebar.=" {$lnc[8]} {$page}/{$total_pages} ";
    $pagebar.=" <"a href=\"{$returnurl}{$conxer}page=1\">\"{$lnc[9]}\" ";
    if ($page!=1) $pagebar.=" <"a href=\"{$returnurl}{$conxer}page=".($page-1)."\">\"{$lnc[10]}\" ";
    for ($i=$firstindexpage; $i<=$lastindexpage; $i++) {
    if ($i!=$page) $pagebar.=" <"a href=\"{$returnurl}{$conxer}page={$i}\">[{$i}] ";
    else $pagebar.=" [{$i}] ";
    }
    if ($page!=$total_pages) $pagebar.=" <"a href=\"{$returnurl}{$conxer}page=".($page+1)."\">\"{$lnc[11]}\" ";
    $pagebar.=" <"a href=\"{$returnurl}{$conxer}page={$total_pages}\">\"{$lnc[12]}\" ";
    return $pagebar;
    }

    function check_upload_file ($filename) { //Check if the file contains dangerous characters
    $danger=array ('fopen', 'fsockopen', 'writetofile', 'unlink', 'exec', 'eval');
    if (!file_exists($filename)) return true;
    $content=@readfromfile($filename);
    foreach ($danger as $checker) {
    if (stristr($content, $checker)) return false;
    }
    return $content;
    }

    function phpcode ($str) { //Convert HTML chars into entities for [CODE]
    $str=str_replace("\\\"", '"', $str);

    $str=htmlspecialchars($str, ENT_QUOTES);
    $str=str_replace('[', '[', $str);
    $str=str_replace(']', ']', $str);
    return "[code]{$str}[/code]";
    }

    function phpcode2 ($str) { //Convert HTML chars into entities for [CODE]
    $str=str_replace("\\\"", '"', $str);
    $str=str_replace('[', '[', $str);
    $str=str_replace(']', ']', $str);
    return "[code]{$str}[/code]";
    }

    function phpcode3 ($str) { //Encode the code for highlight purpose
    $str=str_replace("\\\"", '"', $str);
    $str=base64_encode($str);
    return "[php]{$str}[/php]";
    }

    function phpcode4 ($str) { //Encode the code for highlight purpose
    $str=base64_decode($str);
    $str=htmlspecialchars($str);
    return "[php]{$str}[/php]";
    }

    function admin_convert ($str) {
    global $mqgpc_status;
    $str=stripslashes($str);
    $str=str_replace("\r", '', $str);
    $str=str_replace("\n", '', $str);
    $str=str_replace("'", "\'", $str);
    return $str;
    }

    function confirmpsw() {
    global $logstat, $config, $ajax, $lna, $db_tmpdir, $userdetail, $db_defaultsessdir;
    if ($config['noadminsession']=='1') return;
    if ($db_defaultsessdir!=1) session_save_path("./{$db_tmpdir}");
    session_cache_limiter("private, must-revalidate");
    session_start();
    if ($_SESSION['admin_userid']!==$userdetail['userid'] || $_SESSION['admin_psw']!==$userdetail['userpsw']) {
    if ($ajax=='on') catcherror ($lna[951]);
    $loginjob=($logstat==1) ? 'adminlog' : '';
    header ("Location: login.php?job={$loginjob}");
    exit();
    }
    }

    function checksafe ($str) {
    $array_searches=array('fopen', 'eval', 'fsockopen', '_COOKIE', '_SESSION', 'writetofile', 'fwrite', 'fput', 'exec', 'Location', 'opendir', 'readdir', 'unlink', 'rmdir', 'mkdir', 'chmod', 'rename', 'mysql_', 'mysqli_', 'file_get_contents', 'file_put_contents', 'tmpfile', 'copy');
    return preg_search ($str, $array_searches);
    }

    function reArrayFiles($file_post) {
    $file_ary = array();
    $file_count = count($file_post['name']);
    $file_keys = array_keys($file_post);
    for ($i=0; $i<$file_count; $i++) {
    foreach ($file_keys as $key) {
    $file_ary[$i][$key] = $file_post[$key][$i];
    }
    }
    return $file_ary;
    }

    2007年6月17日 星期日

    使用PHP與AJAX製作RSS閱讀器

    大家應該都有聽過RSS這東西吧!!
    在臺灣常看到人用的閱讀器是YAHOO的和GOOGLE READER 現在就來學習如何在你的網站上加上RSS閱讀器吧!!!
    < ? php // load the list of feeds require_once ('config.php'); ? >
    < ! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional // EN" "http: //www.w3.org/TR/xhtm11/DTD/xhtml1-transitional.dtd" >
    < xmlns="http://www.w3.org/1999/xhtml">
    <>
    < equiv="content-type" content="text/html' charset=utf-8">
    <> PHP 與 ajax RSS 閱讀器 < /title >
    < rel="stylesheet" type= "text/css" href="rss_reader.css">
    < src ="rss_reader.js" type ="text/javascript"> < /script >
    < /head >
    <>
    <>PHP 與 ajax RSS 閱讀器 < / h1>
    < id="feeds">
    <> feeds < /h2>
    < id ="feedlist ">
    < ?php // display feeds for ($ =0; $i < id="feed-' .$i.'">< href="javascript" onclick = "getfeed(document.getelementbyid(\'feed-'.$i.'\'),\' ' .urlencode ( $feeds [$i]['feed']). '\');">';
    echo $feeds[$i]['title'] .'< / a >< / li >';
    }
    ? >
    < /ul>
    < / div>
    < id ="content">
    < id="loading" style="display:none"> loading feed ... < /div>
    < id="feedcontainer" style ="display:none"> < /div>
    < id="home">
    <> about the rss reader < /h2 >
    <>
    這里是秀出首頁主視窗的文字
    < /p >
    < / div>
    < /div >
    < /body >
    < / html >

    這里的只是閱讀器的首頁程式,如果有興趣的人可以留言或寫信給我
    我會在繼續發剩下的程式碼和整合教學

    2007年6月14日 星期四

    使用PHP製作動畫效果

    addFill(0, 0, 0xff);
    $square->setRightFill($sqfill);
    $square->movePenTo(-250,-250);
    $square->drawLineTo(250,-250);
    $square->drawLineTo(250,250);
    $square->drawLineTo(-250,250);
    $square->drawLineTo(-250,-250);

    $sqclip = new SWFSprite();
    $i = $sqclip->add($square);
    $i->setDepth(1);
    $sqclip->setframes(25);
    $sqclip->add(new SWFAction("stop();"));
    $sqclip->nextFrame();
    $sqclip->add(new SWFAction("play();"));
    for($n=0; $n<24;>rotate(-15);
    $sqclip->nextFrame();
    }

    /* 下面製作按鈕 */

    function rect($r, $g, $b) {
    $s = new SWFShape();
    $s->setRightFill($s->addFill($r, $g, $b));
    $s->drawLine(500,0);
    $s->drawLine(0,500);
    $s->drawLine(-500,0);
    $s->drawLine(0,-500);
    return $s;
    }

    $b = new SWFButton();
    $b->addShape(rect(0xff, 0, 0), SWFBUTTON_UP | SWFBUTTON_HIT);
    $b->addShape(rect(0, 0xff, 0), SWFBUTTON_OVER);
    $b->addShape(rect(0, 0, 0xff), SWFBUTTON_DOWN);
    $b->addAction(new SWFAction("setTarget('/box'); gotoandplay(2);"), SWFBUTTON_MOUSEDOWN);

    /* 下面創建動畫,並加上符號和按鈕 */

    $m = new SWFMovie();
    $m->setDimension(4000,3000);

    $i = $m->add($sqclip);
    $i->setDepth(3);
    $i->moveTo(1650, 400);
    $i->setName("box");

    $i = $m->add($b);
    $i->setDepth(2);
    $i->moveTo(1400,900);

    /* 最後,輸出至我們的瀏覽器 */

    header('Content-type: application/x-shockwave-flash');
    $m->output();
    ?>

    2007年6月13日 星期三

    PHP 部落格架設

    最近在研究部落格的製作
    這是留言發表的程式片段

    $begintime=getmicrotime();
    $blogplugin=$section_header=$section_footer=$section_sidebar=$section_prebody=array();

    require_once ("global.php");
    include_once ("data/allmods.php");
    include_once ("data/modules.php");
    include_once ("data/weather.php");
    include_once ("data/cache_emot.php");
    include_once ("data/cache_emsel.php");
    include_once("data/cache_adminlist.php");
    include_once("data/plugin_enabled.php");


    acceptrequest('act,go,page,part');
    if (!isset($page) || !is_numeric($page) || $page<=0) $page=1; else $page=floor($page); $part=floor($part); if (empty($part)) $part=1; $pageitems=''; if ($config['blogopen']!=1 && !defined('isLogin')) { if ($permission['CP']==1) $config['message_off'].="
    • <"a" href="http://www.blogger.com/%27admin.php%27">{ $lnc[107] }
    ";
    catcherror($config['message_off']);
    }

    if ($go) @list($job, $itemid)=@explode('_', basename($go));
    if (!$act) $act='main';
    else $act=basename($act);
    $itemid=safe_convert($itemid);

    //Load Template info
    for ($i=0; $i\n";
    }
    $mbcon['images']=$template['images'];

    //Alert the admin to log in again before he can perform any moderating actions
    if ($permission['CP']=='1') {
    if ($config['noadminsession']=='1') define("ADMIN_LOGIN", 1);
    else {
    if ($db_defaultsessdir!=1) session_save_path("./{$db_tmpdir}");
    session_cache_limiter("private, must-revalidate");
    session_start();
    if ($_SESSION['admin_userid']!==$userdetail['userid'] || $_SESSION['admin_psw']!==$userdetail['userpsw']) {
    if ($act!='login')
    $headerhtml_notifyadmin="
    {$lnc[279]}
    ";
    define("ADMIN_LOGIN", 0);
    } else define("ADMIN_LOGIN", 1);
    }
    } elseif ($permission['ReplyReply']=='1') define("ADMIN_LOGIN", 1);
    else define("ADMIN_LOGIN", 0);

    //Start Template Analyzing
    $t=new template;

    //Start Loading Modules
    if (file_exists("inc/mod_{$act}.php")) include ("inc/mod_{$act}.php");
    else {
    $valid_plugins=@explode(',', $blogplugin['page']);
    if (@in_array($act, $valid_plugins) && is_file("plugin/{$act}/page.php")) { //Load whole page plugin
    include ("plugin/{$act}/page.php");
    if ($plugin_closesidebar==1) $elements['mainpage']=str_replace("class=\"content\"", "class=\"content-wide\"", $elements['mainpage']);
    $bodymenu=$t->set('mainpage', array('pagebar'=>'', 'iftoppage'=>'none', 'ifbottompage'=>'none', 'ifannouncement'=>'none', 'topannounce'=>'', 'mainpart'=>$plugin_return, 'previouspageexists'=>'', 'nextpageexists'=>''));
    }
    else include ("inc/mod_main.php");
    }

    //Section: ..
    $ajax_js="\n";
    $ajax_js.="\n";
    $ajax_js.="\n";
    $ajax_js.="";
    $ajax_js=plugin_walk ('firstheader', $ajax_js);

    include_once ("inc/mod_basic.php");
    include_once ("data/mods.php");
    $extraheader=$mbcon['extraheader']."\n".@implode("\n", $section_prebody);

    $headerhtml=$t->set('header', array('blogname'=>$config['blogname'], 'blogdesc'=>$config['blogdesc'], 'csslocation'=>$csslocation, 'pagetitle'=>$pagetitle, 'ajax_js'=>$ajax_js, "extraheader"=>$extraheader, "blogkeywords"=>$config['blogkeywords'], 'baseurl'=>$baseurl, 'language'=>$langname['languagename'], 'codeversion'=>$codeversion));

    //Admin notification
    $headerhtml.=$headerhtml_notifyadmin;

    //Section: Top
    $section_head_components="
  • ".@implode("
  • \r\n
  • ", $section_header)."
  • ";
    $headmenu=$t->set('displayheader', array('blogname'=>$config['blogname'], 'blogdesc'=>$config['blogdesc'], 'section_head_components'=>$section_head_components));

    //Where am I now?
    if (defined('whereAmI')) $currentpagelocation=whereAmI;
    else {
    $nav=$_SERVER["REQUEST_URI"];
    $currentpagelocation=strrchr($nav, '/');
    $currentpagelocation=str_replace('.php', '', substr($currentpagelocation, 1));
    if ($currentpagelocation=='') $currentpagelocation='index';
    }
    $headmenu_tmp=str_replace(array("", ""), array("", ""), $headmenu);
    $headmenu=($headmenu_tmp==$headmenu) ? str_replace(array("", ""), array("", ""), $headmenu) : $headmenu_tmp;

    //Section: Side
    if ($plugin_closesidebar!=1) {
    if (is_array($section_sidebar)) {
    $siderbarcounter=0;
    foreach ($section_sidebar as $blocker) {
    $blockname="sideblock_{$blocker['name']}";
    if (isset($elements[$blockname])) $sideblock=$blockname;
    else $sideblock="sideblock";
    $ifextend=$blocker['extend'] ? 'block' : 'none';
    $decodedcontent=evalmycode($blocker['content']);
    $section_side_components[]=$t->set($sideblock, array('title'=>$blocker['title'], 'content'=>$decodedcontent, 'id'=>$blocker['name'], 'ifextend'=>$ifextend));
    $tptvalue["block_{$blocker['name']}"]=$decodedcontent;
    $siderbarcounter+=1;
    unset($decodedcontent);
    }
    $section_side_components=@implode('', $section_side_components);
    }
    $sidemenu=$t->set('displayside', array('section_side_components'=>$section_side_components, 'siderbarcounter'=>$siderbarcounter));
    } else $sidemenu='';

    //Section: Bottom
    $section_foot_components=@implode('', $section_footer);
    $footmenu=$t->set('displayfooter', array('section_foot_components'=>$section_foot_components));

    //Section: ..
    $footerhtml=$t->set('footer', array());

    $displayall=array('headerhtml'=>$headerhtml, 'headmenu'=>$headmenu, 'footmenu'=>$footmenu, 'bodymenu'=>$bodymenu, 'sidemenu'=>$sidemenu, 'footerhtml'=>$footerhtml);
    $tt=$t->set('displayall', $displayall);

    $tt=$t->publish($tt); //2006-10-20 Add global setting support

    @header("Content-Type: text/html; charset=utf-8");
    if ($config['gzip']==1) ob_start("ob_gzhandler");

    //Running time
    if ($mbcon['runtime']==1) {
    $endtime=getmicrotime();
    $runtimeamount=$endtime-$begintime;
    $runtimeamount=floor($runtimeamount*1000);
    $gzipplus=($config['gzip']==1) ? ', Gzip enabled' : '';
    $runtimedisplay="";
    $tt=str_replace('', $runtimedisplay.'', $tt);
    }
    echo $tt;
    //print_r ($tptvalue);
    //print_r ($allqueries); //Debug only
    if ($config['gzip']==1) ob_end_flush();


    function getmicrotime() { //Time Counting
    list($usec, $sec) = explode(" ",microtime());
    return ((float)$usec + (float)$sec);
    }

    2007年6月7日 星期四

    亂數密碼產生

    < ?
    /* 產生密碼 */

    /* 亂數產生二十四碼位數 */
    $code = substr("00".rand(1,50)+(39*rand(1,10000)+1),0,2);
    $code = $code.substr("00".rand(1,50)+(39*rand(1,10000)+1),0,2);
    $code = $code.substr("00".rand(1,50)+(39*rand(1,10000)+1),0,2);
    $code = $code.substr("00".rand(1,50)+(39*rand(1,10000)+1),0,2);
    $code = $code.substr("00".rand(1,50)+(39*rand(1,10000)+1),0,2);
    $code = $code.substr("00".rand(1,50)+(39*rand(1,10000)+1),0,2);
    $code = $code.substr("00".rand(1,50)+(39*rand(1,10000)+1),0,2);
    $code = $code.substr("00".rand(1,50)+(39*rand(1,10000)+1),0,2);
    $code = $code.substr("00".rand(1,50)+(39*rand(1,10000)+1),0,2);
    $code = $code.substr("00".rand(1,50)+(39*rand(1,10000)+1),0,2);
    $code = $code.substr("00".rand(1,50)+(39*rand(1,10000)+1),0,2);
    $code = $code.substr("00".rand(1,50)+(39*rand(1,10000)+1),0,2);

    /* 將二十四位數拆成二十四組,兩位數一組。 */
    for($i=1;$i<=24;$i++){
    $temp[$i]=substr("0".$code."0",$i,2);
    }

    /* 設定十二個變數,內容為上面拆出來的變數從中央合併後,再乘上一組一到一萬的亂數,除 36 取餘數(範圍是 0-35 )。 */
    for($i=1;$i<=12;$i++){
    $code_temp[$i]=intval($temp[$i].$temp[$i+1])%60;
    }

    /* 宣告密碼 */
    $password = "";

    /* 組合密碼 */
    for($i=1;$i<=12;$i++){
    if($code_temp[$i]<10){
    $code_temp[$i]=$code_temp[$i]+48;
    } elseif($code_temp[$i]<34) {
    $code_temp[$i]=$code_temp[$i]+55;
    } else {
    $code_temp[$i]=$code_temp[$i]+63;
    }
    $password=$password.chr($code_temp[$i]);
    }
    ?>

    Password =

    Password(md5) =


    /* 運算驗證碼 */

    /* 將 Password 拆成十二組,兩位數一組。 */
    for($i=1;$i<=12;$i++){
    $password_temp[$i]=substr($password,$i,1);
    }

    /* 亂數產生二十四碼位數 */
    for($i=1;$i<=24;$i++){
    $encode = $encode.substr(39*$password_temp[$i]+$i,0,2);
    }

    /* 將二十四位數拆成二十四組,兩位數一組。 */
    for($i=1;$i<=24;$i++){
    $password_temp[$i]=substr($encode,$i,2);
    }

    /* 設定十二個變數,內容為上面拆出來的變數從中央合併後,再乘上一組一到一萬的亂數,除 36 取餘數(範圍是 0-35 )。 */
    for($i=1;$i<=12;$i++){
    $encode_temp[$i]=intval($password_temp[$i].$password_temp[$i+1])%60;
    }

    /* 宣告驗證碼 */
    $encode = "";

    /* 組合驗證碼 */
    for($i=1;$i<=12;$i++){
    if($encode_temp[$i]<10){
    $encode_temp[$i]=$encode_temp[$i]+48;
    } elseif($encode_temp[$i]<34) {
    $encode_temp[$i]=$encode_temp[$i]+55;
    } else {
    $encode_temp[$i]=$encode_temp[$i]+63;
    }
    $encode=$encode.chr($encode_temp[$i]);
    }
    ?>
    Encode = < ? echo $encode; ? >< BR >
    Encode(md5) = < ? echo md5($encode); ? >< BR >