2012-10-03 73 views
2

目前我正在學習一點Coldfusion編碼,並將我的整個舊PHP網站轉換爲流暢的Coldfusion代碼,但我堅持使用PHP的幾行代碼,而且我確實不知道我應該怎麼這行代碼轉換成適當的ColdFusion代碼:將PHP代碼轉換爲Coldfusion

function access() 
{ 
    $accesscode = $_GET["accesscode"]; 
    $time = (int)$_GET["time"];   
    $ip = $_GET["ip"];     

    // Time variable must be identical 
    if(time() < $time) 
     { 
     die("Locale time is ". (time()-$time) ."sec. is not correct."); 
     } 

// Check client IP 
    if($ip <> $_SERVER["REMOTE_ADDR"]) 
     { 
     die("Client IP ".$_SERVER["REMOTE_ADDR"]." is not identical as ".$ip." used."); 
     } 

    // Time > 10 minutes is no access 
    for ($c=0;$c<=3;$c++) 
    { 
    $t = substr(strftime("%Y%m%d%H%M", time()-($c*600)),0,11); 
    $hash = md5($ip. "9709f31be0". $t); 
    if($hash == $accesscode) return true; 
    } 

return false; 
} 

if (!access())  
{ 
    die ("Access denied.."); 
} 
Echo "Access approved."; 

如果有人可以幫助給我如何的這幾行代碼轉換的一些技巧,我會非常greatfull。

非常感謝提前,

+0

什麼困擾你?日期格式化? – LarZuK

+2

你需要更具體,很多這是非常基本的代碼,你可以很容易谷歌「PHP時間()Coldfusion」,並拿出Now()等 – Busches

+0

幾乎所有的,但我會谷歌php time()coldfusion。謝謝。 – Yannick

回答

5

夫婦的你能做到這一點的方式...但我不得不作出一些假設,因爲我不知道很多關於PHP。

<cffunction name="access" access="public" returntype="struct"> 
    <cfargument name="accesscode" type="string" required="yes"> 
    <cfargument name="time" type="string" required="yes"> 
    <cfargument name="ip" type="string" required="yes"> 

    <cfset var temp = StructNew()> 
    <cfset temp.time = Now()> 
    <cfset temp.errormsg = ""> 

    <cfif temp.time lt arguments.time> 
    <cfset temp.errormsg = "(your error message here)"> 
    </cfif> 

    <cfif cgi.remote_addr neq arguments.ip> 
    <cfset temp.errormsg = "(your error message here)"> 
    </cfif> 

    <cfloop index="temp.c" from="0" to="3"> 
    <!--- not entirely sure what you were doing in here ---> 
    </cfloop> 


    <cfreturn temp> 

</cffunction> 

<cfset result = access(accesscode="something", time="something", ip="something")> 

<cfif result.errormsg neq ""> 
    <!--- access denied ---> 
</cfif> 
+0

你不知道該怎麼做的部分只是一個簡單的檢查,如果已經達到了時間限制。例如。在創建代碼(時間字符串)之後,10分鐘後就不能再使用它了。感謝您的幫助! – Yannick